如何加入两个列表<;字符串>;在c#中使用LINQ
我在从SharePoint web services返回的XML元素z:row中有两个单独的国家属性如何加入两个列表<;字符串>;在c#中使用LINQ,c#,asp.net,linq,sharepoint-2010,C#,Asp.net,Linq,Sharepoint 2010,我在从SharePoint web services返回的XML元素z:row中有两个单独的国家属性 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") wh
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();
使用。相反,Concat
不会过滤重复项。var Joinedlist=来自母国的hccountry.AsEnumerable()
country.DataSource = homeCountry
.Union(convCountry)
.ToList();
country.DataBind();
加入covCountry中的coCountry.AsEnumerable()
在共同国家。等于国家。
在homeCountry和covCountry上尝试内部联接。在本例中,Distinct()
是多余的.Union()
保证唯一性。
country.DataSource = homeCountry
.Union(convCountry)
.ToList();
country.DataBind();
var Joinedlist = from hCountry in homeCountry.AsEnumerable()
join coCountry in covCountry.AsEnumerable()
on coCountry.<column Name> equals hCountry.<column Name>