gpt4 book ai didi

c# - default(TSource) 是一个真正的方法吗?

转载 作者:行者123 更新时间:2023-11-30 13:56:31 26 4
gpt4 key购买 nike

MSDN help page on Enumerable.FirstOrDefault Method有一个方法结果解释为:

default(TSource) if source is empty; otherwise, the first element in source.

备注部分包含备注:

The default value for reference and nullable types is null.

我一直在检查 null (VB.NET: Nothing) 值,但是是否有一些 default(TSource) 可以是使用而不是 null/Nothing 文字? (例如 default(int)。)

我找不到 default(TSource) 方法,但在帮助页面上提到了它。或者它不是一种方法?

编辑 default(TSource) 在 C# 和 VB 的 MSDN 页面上可见,我对涵盖这两种语言的答案很感兴趣。

最佳答案

您可以使用 default 运算符,它记录在 here 中.它为引用类型返回 null,为值类型返回类型相关的默认值。

关于c# - default(TSource) 是一个真正的方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27525598/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com