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?
Best Answer
It should be
Length
notCount
for arrays:More information on the MSDN: Array.Length
Also, unless it was intentional, your
ii
should just bei
in yourfor
loop:Although, as was pointed out in the comments below, you could also use the
Quantitys.Count()
, since arrays inherit fromIEnumerable<T>
. Personally, though, for one-dimensional arrays, I prefer to use the standardArray.Length
property.