在泛型类和泛型方法中产生的一个问题是,在预先未知以下情况时,如何将默认值分配给参数化类型 T:
T 是引用类型还是值类型。
如果 T 为值类型,则它是数值还是结构
http://msdn.microsoft.com/zh-cn/library/xwth0h0d.aspx
1
2
3
4
5
6
7
8
9
10
11
12
13 |
//T a = default(T); int i = default ( int ); Console.WriteLine(i); Console.WriteLine( default ( int )); Console.WriteLine( default (DateTime)); Console.WriteLine( default ( bool )); Console.WriteLine( default ( decimal )); Console.WriteLine( default ( string )); Console.WriteLine( default ( string ) == null ); Console.WriteLine( default ( string )== "" ); Console.WriteLine( default ( string )== string .Empty); |
输出结果:
原文:http://www.cnblogs.com/i-blog/p/3547592.html