gpt4 book ai didi

c# - List 需要 '1' 类型参数

转载 作者:太空宇宙 更新时间:2023-11-03 18:29:12 24 4
gpt4 key购买 nike

我正在阅读这本书

http://hookedonlinq.com/LINQBook.ashx

但是当我尝试实现这段代码时

public class Contact
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public DateTime DateOfBirth { get; set; }
public string State { get; set; }

public static List SampleData()
{
return new List {
new Contact { FirstName = "Barney", LastName = "Gottshall", DateOfBirth = new DateTime(1945,10,19), Phone = "885 983 8858", Email = "bgottshall@aspiring–technology.com", State = "CA" },
new Contact { FirstName = "Armando", LastName = "Valdes", DateOfBirth = new DateTime(1973,12,09), Phone = "848 553 8487", Email = "val1@aspiring–technology.com", State = "WA" },
new Contact { FirstName = "Adam", LastName = "Gauwain", DateOfBirth = new DateTime(1959,10,03), Phone = "115 999 1154", Email = "adamg@aspiring–technology.com", State = "AK" },
new Contact { FirstName = "Jeffery", LastName = "Deane", DateOfBirth = new DateTime(1950,12,16), Phone = "677 602 6774", Email = "jeff.deane@aspiring–technology.com", State = "CA" },
new Contact { FirstName = "Collin", LastName = "Zeeman", DateOfBirth = new DateTime(1935,02,10), Phone = "603 303 6030", Email = "czeeman@aspiring–technology.com", State = "FL" },
new Contact { FirstName = "Stewart", LastName = "Kagel", DateOfBirth = new DateTime(1950,02,20), Phone = "546 607 5462", Email = "kagels@aspiring–technology.com", State = "WA" },
new Contact { FirstName = "Chance", LastName = "Lard", DateOfBirth = new DateTime(1951,10,21), Phone = "278 918 2789", Email = "lard@aspiring–technology.com", State = "WA" },
new Contact { FirstName = "Blaine", LastName = "Reifsteck", DateOfBirth = new DateTime(1946,05,18), Phone = "715 920 7157", Email = "blaine@aspiring–technology.com", State = "TX" },
new Contact { FirstName = "Mack", LastName = "Kamph", DateOfBirth = new DateTime(1977,09,17), Phone = "364 202 3644", Email = "mack.kamph@aspiring–technology.com", State = "TX" },
new Contact { FirstName = "Ariel", LastName = "Hazelgrove", DateOfBirth = new DateTime(1922,05,23), Phone = "165 737 1656", Email = "arielh@aspiring–technology.com", State = "OR" } };
}
}

我收到错误 System.Collections.Generic.List requires '1' type arguments 我知道 List 需要定义为 eg

List<string>

List<int>

但无法确定列表应该是什么。谁能帮忙?

谢谢

最佳答案

public static List<Contact> SampleData()

...

return new List<Contact> { ....

...因为您要放入列表中的对象是 Contact

理解泛型的一个简单方法是使用“of”这个词,例如List<Contact>等同于说“联系人列表”

关于c# - List<T> 需要 '1' 类型参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26212336/

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