Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have 2 separate country attributes in the XML element z:row, returned from SharePoint web services.

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);

Now I want to merge both of the lists, in order to get the distinct country names and load the dropdow dox.

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

        country.DataBind();
like image 229
foo-baar Avatar asked Mar 27 '26 23:03

foo-baar


2 Answers

var distinctCountriesList = homeCountry.Union(covCountry).ToList();
like image 132
Daniel A. White Avatar answered Mar 29 '26 12:03

Daniel A. White


country.DataSource = homeCountry
    .Union(convCountry)
    .ToList();

country.DataBind();
like image 41
Viacheslav Smityukh Avatar answered Mar 29 '26 13:03

Viacheslav Smityukh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!