小编Ein*_*ssy的帖子

获取未知类型的方法并运行它c#

我有一个抽象类(Parent),其函数名为funcA.Parent有4个childern,用户需要选择访问哪个.我需要做的是访问用户选择的子子类中的覆盖方法funcA并激活它.

家长:

public abstract class Parent
{
 public string PropA {get; set;}
 public string PropB {get; set;}
 public DateTime PropC {get; set;}
 public DateTime PropD {get; set;}

 public abstract void FuncA();

}
Run Code Online (Sandbox Code Playgroud)

儿童:

public class ChildA: Parent
{
   public string PropE {get; set;}
   public string PropF {get; set;}

   public override void FuncA()
   {
     // Some Code
   }
}
Run Code Online (Sandbox Code Playgroud)

主要:

public static void Main(string[] args)
{
  Console.WriteLine("Enter the type of child: ");
  string type = Console.Readline();

  // I need to identify …
Run Code Online (Sandbox Code Playgroud)

c# inheritance

4
推荐指数
1
解决办法
152
查看次数

标签 统计

c# ×1

inheritance ×1