gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 22:16:14 24 4
gpt4 key购买 nike

如果我在 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/

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