C#父类与子类之间关系的妙用
namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { Console.WriteLine("Hello, World!"); AppleClass AppleClass = new AppleClass(); AppleClass.Name = "apple"; AppleClass.Ap = "ap"; Fruilt fruilt = (Fruilt)AppleClass; if (fruilt.FruiltType == EnumFruiltType.Apple) { var aa = (AppleClass)fruilt; } } public class Fruilt { public EnumFruiltType FruiltType { get; set; } public string Name { get; set; } } public class AppleClass : Fruilt { public string Ap { get; set; } public AppleClass() { FruiltType = EnumFruiltType.Apple; } } public class OrangeClass : Fruilt { public string or { get; set; } public OrangeClass() { FruiltType = EnumFruiltType.Orange; } } public enum EnumFruiltType { Apple = 0, Orange = 1 } } }