【发布时间】:2018-05-27 12:08:36
【问题描述】:
我有列表,我需要搜索特定项目并从该列表中获取相关数据。
public People(string name, string talent)
{
Name= name;
Talent= talent;
}
public string Name;
public int Talent;
我在该列表中添加了许多项目
List<People> peopleList = new List<People>();
For example;
"John","magic",
"John","windpower",
"John","electricpower",
"John","firepower",
"Luigi","storm",
"Luigi","fire",
我正在努力让所有人才都喜欢;
string talentsofJohn = "magic,windpower,electricpower,firepower";
string talentsofLuigi = "storm,fire";
我尝试了很多方法,尤其是 Linq,但无法做到;
var talentsofJohn = peopleList.Find(item => item.name == "John");
【问题讨论】:
-
People 是复数;你的班级最好命名为“人”
-
CaiusJard 对不起我的英语这是我最好的:) @ThrowingSpoon 是的名字是独一无二的