gpt4 book ai didi

c# - 通用 List.Count 给出 System.ArgumentException

转载 作者:行者123 更新时间:2023-11-30 18:43:43 25 4
gpt4 key购买 nike

我有以下类(class):

public class SimContactDetails2G
{
public String AbreviatedName { get; set; }
public String DialingNumber { get; set; }
public int Index { get; set; }
public String Surname { get; set; }

public SimContactDetails2G()
{

}

public SimContactDetails2G(String name, String phoneNumber)
{
AbreviatedName = name;
DialingNumber = phoneNumber;
}

}

我想创建一个包含上述对象的列表。我也是,

List<SimContactDetails2G> simContactDetails2GToBackUp = new List<SimContactDetails2G>();

但是,当我尝试检索变量“simContactDetails2GToBackUp”上的项目数时,出现以下错误:

Count = '((System.Collections.Generic.List<T>)(simContactDetails2GToBackUp)).Count' threw an exception of type 'System.ArgumentException'

程序没有崩溃,但我无法访问计数属性。我可以在列表中添加项目,列表已填充。但我无法得到计数。对这种奇怪的行为有什么想法吗?

最佳答案

你为什么转换到 List<T>而不是 List<SimContactDetails2G>

关于c# - 通用 List.Count 给出 System.ArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3965949/

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