c# .net

How to select distinct records from list in c# Linq and bind to a combobox?

How to select distinct records from list in c# Linq and bind to a combobox?, someone asked me to explain?

In this example, I will show you to select distinct records from list in linq and bind to a combobox in windows application using c# .net.

I want to bind the list of countries to a combobox using c# .net. The linq Distinct() guarantees to remove duplicate records from the List.

  private void LoadCountries()
        {
            var countries = (from c in db.Orders
                             select new { c.ShipCountry }).Distinct().ToList();
            cboCountry.DataSource = countries;
            cboCountry.ValueMember = "shipcountry";
            cboCountry.DisplayMember = "shipcountry";

        }

 

select distinct records from list in c# Linq

Post your comments / questions