如何使用或调用列表中的数据< List< String>> [英] How Can I Use Or Call The Data In List<List<String>>

查看:73
本文介绍了如何使用或调用列表中的数据< List< String>>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们使用列表时,我们可以通过点索引使用它们像 Somelisr [0] Somlist [1 ],但我如何使用列表中的数据< list> ;任何人请指导我



或任何人都有最简单的方式使用它,请在这里我真的需要知道我们的代码



列表< list>< string>> Wayfinder =  new 列表< list>< string>>(); 

Wayfinder.Add( new 列表< string> { a b});
Wayfinder.Add( new List< string> { c d});
Wayfinder.Add( new List< string> { e f});
Wayfinder.Add( new List< string> { g h i j });





PS;好吧,我必须得到每个数据并使用intersec或union来找到那些lise中的相​​同数据。



添加了代码块< /小>

解决方案
如果你的意思是:

<预郎= C#>列表与LT;列表> <串GT;> Wayfinder = new 列表< list>< string>>();

Wayfinder.Add( new 列表< string> { a b});
Wayfinder.Add( new List< string> { c d});
Wayfinder.Add( new List< string> { e f});
Wayfinder.Add( new List< string> { g h i j }); < / string > < / string > < / string > < / string > < / string > < / 列表 > < / 字符串 > < ; / 列表 >


 List< string> union =  new  List< string>(); 
foreach (List< string> list in Wayfinder)
{
union.AddRange(list);
}
union = union.Distinct()。OrderBy(u = > u).ToList(); < / string > < / 字符串 > < / string >



交点大致相同:

 List< string> intersection = Wayfinder [ 0 ]; 
for int i = 1 ; i < Wayfinder.Count; i ++)
{
intersection = intersection.Intersect(Wayfinder [i])。ToList() ;
} < / string >

但在你的例子中,它将是一个空列表。


when we use a list we can call use them like Somelisr[0] Somlist[1] by point the index but how can i use the data in list<list> any one guide me please

or anyone have an easyiest way to use it , Please Shere i really need to know here us my code

List<list><string>> Wayfinder = new List<list><string>>();

        Wayfinder.Add(new List<string> { "a", "b" });
        Wayfinder.Add(new List<string> { "c", "d" });
        Wayfinder.Add(new List<string> { "e", "f" });
        Wayfinder.Add(new List<string> { "g", "h","i","j" });



PS; well, i have to get each of it data and use intersec or union to find the same data in those lise .

code block added

解决方案

If what you mean is:

List<list><string>> Wayfinder = new List<list><string>>();

Wayfinder.Add(new List<string> { "a", "b" });
Wayfinder.Add(new List<string> { "c", "d" });
Wayfinder.Add(new List<string> { "e", "f" });
Wayfinder.Add(new List<string> { "g", "h","i","j" });</string></string></string></string></string></list></string></list>


then you can find the union easily by using Linq:

List<string> union = new List<string>();
foreach (List<string> list in Wayfinder)
    {
    union.AddRange(list);
    }
union = union.Distinct().OrderBy(u => u).ToList();</string></string></string>


Intersection is much the same:

List<string> intersection = Wayfinder[0];
for (int i = 1; i < Wayfinder.Count; i++)
    {
    intersection = intersection.Intersect(Wayfinder[i]).ToList();
    }</string>

But in your example, it will be an empty list.


这篇关于如何使用或调用列表中的数据&lt; List&lt; String&gt;&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆