Distinct Strings in List - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Distinct Strings in List

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Linq;
using System.IO;/*from   w  w  w . j a  va  2 s  . c  o m*/
using System.ComponentModel;
using System.Collections.Generic;
using System;

public class Main{
    public static List<string> DistinctStrings(this List<string> items)
      {
         var r = new List<string>();
         foreach (var item in items)
         {
            if (!r.Contains(item))
            {
               r.Add(item);
            }
         }
         return r;
      }
}

Related Tutorials