c# - 为什么 .Count 在没有括号的情况下工作?

标签 c#

如果我在 C# 中有一个项目列表(例如 List<string> items),我可以同时使用两者:

items.Count()

items.Count

获取项目总数。有没有理由让他们都可用?为什么不直接使用 .Count() 方法呢? ?

我注意到如果我过滤列表(并以 IEnumerable<string> 结尾):

items.Distinct().Count()

然后 .Count()必须使用。那么为什么 List<string>允许 .Count有没有?

最佳答案

因为一个是 (LINQ) extension methodSystem.Linq.Enumerable 上,另一个是 property on the class .

关于c# - 为什么 .Count 在没有括号的情况下工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20517988/

相关文章:

c# - regex.replace 查询字符串参数

c# - 隐藏 DateTimePicker 的文本和 Usercontrol 调整大小

c# - Sharepoint 字段或属性 "Body"不存在 ServerException

c# - 用 C# 创建 Form2 并对其进行编辑

c# - 创建 Windows 窗体 打开新窗体

c# - 将样式库加载到 WPF 中

c# - 算术运算导致 tweetsharp 溢出异常

c# - 在 Azure 云服务项目中发布内容文件

c# - docker 应用程序中的 `new HttpRequestMessage(...)` 无法访问互联网?

c# - .NET DateTime Parse 抛出异常