我有这段代码可以查看从 SQL Server 存储过程返回了多少不同的字段/列(dtPriceComplianceResults 是一个已填充了 SP 结果的数据表):
string[] columnNames = dtPriceComplianceResults.Columns.Cast<DataColumn>()
.Select(x => x.ColumnName)
.ToArray();
当我直接在下面添加这段代码时:
if (columnNames.
...Intellisense 给了我一个“Count”选项;但是,当我选择 Enter 键接受它时,它会将它变成“长度”- 它不会让我选择“计数”,即使它在要访问的可用属性列表中也是如此。
注意:“变形”是指当我按下“Enter”时附加到“columnNames”的文本。是“Length”而不是“Count”,所以它最终是“columnNames.Length”
它确实以这种方式编译(使用“长度”),而对于“计数”则不是(“运算符'>'不能应用于'方法组'和'int'类型的操作数").
我想这是一件好事,但如果“计数”不是真正可选的,为什么它会出现在列表中?
最佳答案
It's a ReSharper 10 "typo protection" option :
Correcting Length/Count mistyping
ReSharper prevents you from stumbling over mistyped Length/Count properties of arrays/collections. As soon as you erroneously start typing the Count property for a usage of an array, ReSharper will allow you to pick it from the completion list and replace with the Length property, which you probably meant to type.
您可以在成员信息弹出窗口(IntelliSense 下拉菜单右侧的工具提示)中看到它将被替换为 System.Array.Length
。
如果您想要 Count()
扩展方法,则必须选择前面带有粉红色带箭头扩展方法图标的 Count 选项,而不是顶部带有灰色自动完成的选项图标:
关于c# - 为什么字符串数组的 "Count"Intellisensed 属性会变形为 "Length"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34323222/