[英]How can i refer to variables of a list within a list, C#
I would like to retrieve a the values of a list in a group of lists.我想在一组列表中检索一个列表的值。 Im trying to search through the names of my people in the list of people and return the variables there in. Im also trying to pull from the list favMusic.
我试图在人员列表中搜索我的人员的姓名并返回其中的变量。我还试图从列表 favMusic 中提取。 What is the best way to do this, I have tried various strategies to no avail.
最好的方法是什么,我尝试了各种策略都无济于事。 Basically a huge list of people that I need to be able to search through by name and return that persons info.
基本上,我需要能够按姓名搜索并返回该人员信息的大量人员列表。 Graci
格拉西
public class listofPeople
{
public List<PeopleList> PeopleList;
}
public class PeopleList
{
public string name ;
public string description;
public string favFood ;
public string location ;
public string[] favMusic;
}
Assuming you have a variable that holds all the data, let's call it allPeoples
.假设您有一个包含所有数据的变量,我们称之为
allPeoples
。
var johnProf = allPeoples.FrirstOrDefault(person => person.name.Equals("John"));
If (johnProf != null) {
string[] johnsFavMusic = johnProf.favMusic;
// print or do what you need to do with this list
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.