我想通过仅用字符串标识对象来获取 List 中项目的值
string A ="some_string";
listobject.Add(fruit[0].A);
public class apple
{
public string labbnummer { get; set; }
public string red { get; set; }
public string gren { get; set; }
public string blue { get; set; }
public string purple { get; set; }
}
public List<apple> fruit = new List<apple>();
public List<apple> rutten_fruit = new List<apple>();
List<string> myfruitlist = new List<string>();
myfruitlist.Add("green");
myfruitlist.Add("red");
public void populate{
while (reader.Read())
{
apple tasty = new apple();
tasty.green = (string)reader["green"];
tasty.red = (string)reader["red"];
if (list_nr == 0) { fruit.Add(tasty); }
}
public void orange(){
foreach (var items in myfruitlist)
{
var A =items;
rutten_fruit.Add(fruit[0].A.ToString());
}
}
它不接受 listobject.Add(fruit[0].A); A 作为标识符
LEATH
相关分类