1.运算符:创建对象实例
Class C1 = new Class();
2.修饰符:在派⽣类定义⼀个重名的成员,隐藏掉基类中的成员
public class Program: BaseClass { new public class Test//2、new修饰符 显式隐藏从基类继承的成员 { public int x = 2; public int y = 20; public int z = 40; } static void Main(string[] args) { var c1 = new Test();//1、new操作符 创建对象和调用构造函数 var c2 = new BaseClass.Test(); Console.WriteLine(c1.x);//2 Console.WriteLine(c2.y);//10 Console.ReadKey(); } } public class BaseClass { public class Test { public int x = 0; public int y = 10; } }
3.约束:泛型约束定义,约束指定泛型类声明中的任何类型参数都必须具有公共的无参数构造函数,即T必须有无参的构造函数
public class ItemFactory<T> where T : IComparable, new() { }标签:C#,public,int,Test,new,用法,class,构造函数 From: https://www.cnblogs.com/budongdong/p/17073804.html