简体   繁体   English

我如何在列表中引用列表的变量,C#

[英]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.

相关问题 如何使数据表中的每一行都引用Visual List C#中的项目? - How do I make each Row in a Datatable refer to an item in a Visual List C#? 如何引用列表中的哪个元素触发了事件C# - how to refer which element of my list triggered the event c# Unity C#:如何返回动画组件内变量的列表/数组/长度? - Unity C#: how can i return a list/array/length of the variables inside an animator component? 我如何允许C#添加另一种类型的结构以在其中添加或添加相同类型的列表? - how i can allow C# to add another type of structure to add within or add list of same type? 如何使用c#在ASPX页面中获取IIS中的网站列表? - How can i get a list of the websites in IIS from within a ASPX page using c#? 如何在 signalr javascript 文件中使用 C# 列表? - How can I use a C# list within signalr javascript file? 如何在c#中使用foreach在列表内创建列表? - How can I create a list inside a list with a foreach in c# ? 如何投放清单 <BaseClass> 列出 <ChildClass> 在C#中? - How can I cast List<BaseClass> to List<ChildClass> in C#? 如何根据 C# 中列表中的列表值对列表进行排序? - How to Sort a List based on the value of a list within the list in C#? C#-努力访问列表中对象的变量 - C# - Struggling to access variables for object within a list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM