gpt4 book ai didi

c# - 运算符不能应用于类型为 'Method Group' 和 'int' 的操作数

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

我正在尝试获取此字符串数组中元素的数量,但它不会让我从 Count 中减去 1。

string [] Quantitys = Program.RecieptList[i].ItemQuantitys.Split(new char[] {'*'});
for (int ii = 0; i <= Quantitys.Count - 1; ii++)
{

}

我收到一条错误消息,指出

Operator '-' cannot be applied to operands of type 'Method Group' and 'Int'.

执行此操作的正确方法是什么?

最佳答案

应该是Length不是Count对于数组:

string [] Quantitys = Program.RecieptList[i].ItemQuantitys.Split(new char[] {'*'});
for (int ii = 0; i <= Quantitys.Length - 1; ii++)
{

}

有关 MSDN 的更多信息:Array.Length

此外,除非是故意的,否则您的 ii应该只是 i在你的for循环:

for (int i = 0; i <= Quantitys.Length - 1; i++)

尽管如以下评论中所指出的,您也可以使用 Quantitys.Count() , 因为数组继承自 IEnumerable<T> .不过,就我个人而言,对于一维数组,我更喜欢使用标准 Array.Length属性(property)。

关于c# - 运算符不能应用于类型为 'Method Group' 和 'int' 的操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19526702/

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