zoukankan      html  css  js  c++  java
  • C#中抽象类

    C#中方法的返回值类型是抽象类型:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading;
     6 using System.Text.RegularExpressions;
     7 
     8 namespace Delegate_Event
     9 {
    10     class Program
    11     {
    12         static void Main(string[] args)
    13         {
    14  //返回抽象类类型,实际调用的子类的方法 
    15             var b = new C().getA("D");
    16             b.b();
    17 
    18 
    19             Console.WriteLine(b.b() + "||" + b.t());
    20         }
    21     }
    22 
    23     public abstract class A
    24     {
    25         public A() { }
    26         public virtual string t() { return "123A"; }
    27         public virtual string b() { return "123A"; }
    28     }
    29 
    30     public class B : A
    31     {
    32         public override string t()
    33         {
    34             return "123B";
    35         }
    36 
    37         public override string b()
    38         {
    39             return "123B";
    40         }
    41     }
    42 
    43     public class D : A
    44     {
    45         public override string t()
    46         {
    47             return "123D";
    48         }
    49 
    50         public override string b()
    51         {
    52             return "123D";
    53         }
    54     }
    55 
    56     public class C
    57     {
    58         public A getA(string type)
    59         {
    60             switch (type)
    61             {
    62                 case "B":
    63                     return new B();
    64                 case "D":
    65                     return new D();
    66                 default:
    67                     return new B();
    68             }
    69         }
    70     }
    71 }
  • 相关阅读:
    mysql-proxy使用中的问题
    iOS中利用CoreTelephony获取用户当前网络状态(判断2G,3G,4G)
    Django连接MySQL出错
    前后端分离
    django 安装指定版本
    问题
    算法面试
    记录docker for windows 时候的错误
    Django项目部署
    git 上传至github
  • 原文地址:https://www.cnblogs.com/manyiString/p/abstruct.html
Copyright © 2011-2022 走看看