C# 将项添加到列表对象c中的属性(列表对象类型)#
或 或C# 将项添加到列表对象c中的属性(列表对象类型)#,c#,linq,C#,Linq,或 或 您需要在temp的构造函数或初始值设定项中构建tables集合: table table = new table(); foreach (temp tem in lst_temp) { if(tem.name = "CUS") tem.tables.Add(table); } class-temp { 公共列表表{get;set;} 公共字符串名称{get;set;} 公共临时工() { tables=新列表(); } } 您需要在temp的构造函
您需要在
temp
的构造函数或初始值设定项中构建tables集合:
table table = new table();
foreach (temp tem in lst_temp)
{
if(tem.name = "CUS")
tem.tables.Add(table);
}
class-temp
{
公共列表表{get;set;}
公共字符串名称{get;set;}
公共临时工()
{
tables=新列表();
}
}
您需要在temp
的构造函数或初始值设定项中构建tables集合:
table table = new table();
foreach (temp tem in lst_temp)
{
if(tem.name = "CUS")
tem.tables.Add(table);
}
class-temp
{
公共列表表{get;set;}
公共字符串名称{get;set;}
公共临时工()
{
tables=新列表();
}
}
或在C#6+:公共列表表{get;set;}=new List
@ainwood是的,这就是我所说的“或在初始值设定项中”或在C#6+:公共列表表{get;set;}=new List
@ainwood是的,这就是我所说的”或在初始值设定项中“这里有点错误-您不能有与类名相同的成员名。”(表)对象类型在使用它之前需要创建instant。这里有点错误-您不能让成员名称与类名称(表)对象类型在使用它之前需要创建instant相同。
table table = new table();
lst_temp_syn.Where(x => x.name == "CUS")
.Select(x => { x.tables.Add(table); return x; })
.ToList();
table table = new table();
foreach (temp tem in lst_temp)
{
if(tem.name = "CUS")
tem.tables.Add(table);
}
class temp
{
public List<table> tables { get; set; }
public string name { get; set; }
public temp()
{
tables = new List<table>();
}
}