c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
c# .net

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

| | CSharp , Linq

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

        }