如果程序中有某些类,我将使用名称填充数组。
string[] arr= new string[] {"company", "pokemon", "parents"}
是否可以创建这样的类的实例:
list.Add(new class( arr[0] { "sdfs", "sfds", 123} ))
答案 0 :(得分:1)
也许您正在寻找对象初始化程序?
假设您有Pokemon
类:
class Pokemon {
public string Name { get; set; }
public string Type { get; set; }
public int Age { get; set; }
}
和名为List<Pokemon>
的{{1}},您可以执行以下操作:
list