当前第2页 返回上一页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public class GenericClass< T >
{
public T Function(arg)
{
T temp = default(T);
if (arg != null) temp = arg.Favs;
return temp;
}
//...
}
注意:不仅可以在定义泛型类或者泛型方法的代码中可以使用default关键字,甚至在任何地方都可以使用该关键字
如下面代码。
static void Main(string[] args)
{
Console.WriteLine(default(int));
Console.WriteLine(default(string));
Console.WriteLine(default(Color));
}
|
输出:
1 2 3 | 行1: 0
行2:
行3: Color [Empty]
|
以上就是C#中default什么意思的详细内容!
返回前面的内容
相关阅读 >>
ants performance profiler(.net性能调优教程)
c#中list的用法
c# 7.0 语言新特性
分享多个c#常用正则表达式的实例
c#thread同步mutex的代码详解
c#基于正则表达式如何删除字符串中数字或非数字的方法详解
c# sleep延时方法
.net和c#有什么区别
采用 c# 编写的学委助手详解及实例
c# 实现 cachehelper
更多相关阅读请进入《default》频道 >>
清华大学出版社
作者:[美]克里斯琴·内格尔(Christian Nagel)著。出版时间:2019年3月。
转载请注明出处:木庄网络博客 » C#中default什么意思