繁体   English   中英

如何加入两个List <string> 在c#中使用LINQ

[英]How to join two List<string> in c# using LINQ

我在XML元素z:row中有两个单独的国家/地区属性,从SharePoint Web服务返回。

var homeCountry = (from xml in doc.Descendants(z + "row") select xml.Attribute("ows_Country").Value).Distinct();

    var covCountry = (from xml in doc.Descendants(z + "row")
                      where xml.Attribute("ows_Coverage_x0020_Area_x0020_by_x00").Value != ""
                      select xml.Attribute("ows_Coverage_x0020_Area_x0020_by_x00").Value);

现在我想合并两个列表,以获取不同的国家/地区名称并加载dropdow dox。

distinctCountriesList.Add("");
        distinctCountriesList.Sort();
        country.DataSource = distinctCountriesList.Distinct();

        country.DataBind();
var distinctCountriesList = homeCountry.Union(covCountry).ToList();
country.DataSource = homeCountry
    .Union(convCountry)
    .ToList();

country.DataBind();

使用Union方法 相比之下, Concat不会过滤重复项。

var Joinedlist = from hCountry in homeCountry.AsEnumerable()
                 join coCountry in covCountry.AsEnumerable()
                 on coCountry.<column Name> equals hCountry.<column Name>     

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM