Sen*_*cob 3 c# oop static tuples c#-4.0
在这个链接微软说,
静态类无法实例化.换句话说,您不能使用new关键字来创建类类型的变量.因为没有实例变量,所以可以使用类名本身访问静态类的成员.
我学习了静态类,如上所述.但是对于.NET Framework 4中引入的静态类Tuple,可以使用new关键字来创建元组.
var population = new Tuple("New York",7891957,7781984,7894862,7701639,7322564,8008278);
任何人都可以解释这是怎么可能的?
的元组类是静态的,不能被实例化。
// does not compile
var population = new Tuple("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278);
Run Code Online (Sandbox Code Playgroud)
还有另一个类,Tuple<T1, T2, T3, T4, T5, T6, T7> Class。这个类不是静态的,可以实例化。
// compiles
var population = new Tuple<string, int, int, int, int, int, int>("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278);
Run Code Online (Sandbox Code Playgroud)