Distinct value in List - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Distinct value in List

Demo Code

// Permission is hereby granted, free of charge, to any person
using System.Globalization;
using System.Linq;
using System.Collections;
using System.Text;
using System.Reflection;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System;/*from   ww  w.  j a v a2  s .c  o m*/

public class Main{
        public static List<T> Distinct<T>(List<T> collection)
    {
      List<T> distinctList = new List<T>();

      foreach (T value in collection)
      {
        if (!distinctList.Contains(value))
          distinctList.Add(value);
      }

      return distinctList;
    }
}

Related Tutorials