复制MSDN的。new 运算符(C# 参考) 用于创建对象和调用构造函数。例如: Class1 o = new Class1(); 还可用于创建匿名类型的实例: var query = from cust in customers select new {Name = cust.Name, Address = cust.PrimaryAddress}; new 运算符还用于调用值类型的默认构造函数。例如: int i = new int(); 在上一个语句中,i 初始化为 0,它是 int 类型的默认值。该语句的效果等同于: int i = 0;
用于创建对象和调用构造函数。例如:
Class1 o = new Class1();
还可用于创建匿名类型的实例:
var query = from cust in customers
select new {Name = cust.Name, Address = cust.PrimaryAddress};
new 运算符还用于调用值类型的默认构造函数。例如:
int i = new int();
在上一个语句中,i 初始化为 0,它是 int 类型的默认值。该语句的效果等同于:
int i = 0;