您只有一个基类虚拟函数,如何从已删除的类中调用 [英] You have one base class virtual function how will you call from derieved class

查看:83
本文介绍了您只有一个基类虚拟函数,如何从已删除的类中调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您有一个基类虚函数,您将如何从已删除的类中调用

You have one base class virtual function how will you call from derieved class

推荐答案

,请参见下文
see below
public class Base
{
   public Base(){}
   public virtual void show(string message)
   {
      //Your Logic
   }
}

public class Derived
{
// Only if  you want to override base class show method
   public override void show(string message)
   {
      //Your Logic to override 
   }
}

public class CallFunction
{
    public static void Main()
    {
       Derived obj = new Derived()
       obj.show("Hii");
    }
}


您好,

可以重新定义虚拟方法.在C#语言中,虚拟关键字指定一种可以在派生类中重写的方法.这使您可以添加新的派生类型,而无需修改程序的其余部分.因此,对象的运行时类型决定了程序的作用.

看下面的例子,希望你能理解.
http://www.vijaymukhi.com/documents/books/csbasics/chap9.htm [ ^ ]
http://www.akadia.com/services/dotnet_polymorphism.html [ http://www.dotnetperls.com/virtual [
Hello,

A virtual method can be redefined. In the C# language, the virtual keyword designates a method that can be overridden in derived classes. This enables you to add new, derived types without modifying the rest of your program. The runtime type of objects thus determines what your program does.

Have a look at following examples, hope you will understand.
http://www.vijaymukhi.com/documents/books/csbasics/chap9.htm[^]
http://www.akadia.com/services/dotnet_polymorphism.html[^]
http://www.dotnetperls.com/virtual[^]


Hey hii,
Please Refer below links, May be it will helpful for you:


1)
http://stackoverflow.com/questions/448258/calling-virtual- method-in-base-class-constructor [ ^ ]
2) http://www.dotnetperls.com/inheritance [


1) http://stackoverflow.com/questions/448258/calling-virtual-method-in-base-class-constructor[^]
2) http://www.dotnetperls.com/inheritance[^]


这篇关于您只有一个基类虚拟函数,如何从已删除的类中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆