运营商不能应用到类型'方法组'和'廉政'的操作数 [英] Operator cannot be applied to operands of type 'Method Group' and 'int'
问题描述
我试图进入这个字符串数组元素的数量,但它不会让我拿1远离计数
。
I'm trying to get the number of elements in this string array, but it won't let me take 1 away from Count
.
string [] Quantitys = Program.RecieptList[i].ItemQuantitys.Split(new char[] {'*'});
for (int ii = 0; i <= Quantitys.Count - 1; ii++)
{
}
我得到一个错误信息,说明
I get an error message stating
运算符 - 不能应用于类型的操作数的方法组和诠释。
Operator '-' cannot be applied to operands of type 'Method Group' and 'Int'.
请告诉我正确的方式做到这一点?
Whats the proper way to do this?
推荐答案
这应该是长度
不是计数
的数组:
string [] Quantitys = Program.RecieptList[i].ItemQuantitys.Split(new char[] {'*'});
for (int ii = 0; i <= Quantitys.Length - 1; ii++)
{
}
在MSDN的更多信息: Array.Length
另外,除非是故意的,你的 II
应该仅仅是 I
在为
循环:
Also, unless it was intentional, your ii
should just be i
in your for
loop:
for (int i = 0; i <= Quantitys.Length - 1; i++)
虽然,在下面的评论中指出的那样,你也可以使用 Quantitys.Count()
,因为数组从继承了IEnumerable&LT; T&GT;
。就个人而言,虽然,对于一维数组,我preFER使用标准 Array.Length
属性。
Although, as was pointed out in the comments below, you could also use the Quantitys.Count()
, since arrays inherit from IEnumerable<T>
. Personally, though, for one-dimensional arrays, I prefer to use the standard Array.Length
property.
这篇关于运营商不能应用到类型'方法组'和'廉政'的操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!