Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,924 questions

51,857 answers

573 users

How to remove duplicate sets of items from a list in C#

2 Answers

0 votes
using System;
using System.Collections.Generic;

namespace ConsoleApplication_C_Sharp
{
    static class Program
    {
        public static List<string> RemoveDuplicatesSet(List<string> items)
        {
            var result = new List<string>();

            for (int i = 0; i < items.Count; i++) {
                if (!result.Contains(items[i])) {
                    result.Add(items[i]);
                }
            }
            return result;
        }

        static void Main()
        {
            var list = new List<string>() { "c", "c", "c++", "c#", "c#", "java", "php" };

            list = RemoveDuplicatesSet(list);

            Console.WriteLine(string.Join(" ", list));
        }
    }
}


/*
run:
  
c c++ c# java php
   
*/

 



answered Aug 27, 2018 by avibootz
0 votes
using System;
using System.Collections.Generic;

namespace ConsoleApplication_C_Sharp
{
    static class Program
    {
        public static List<T> RemoveDuplicatesSet<T>(List<T> items)
        {
            var result = new List<T>();

            for (int i = 0; i < items.Count; i++) {
                if (!result.Contains(items[i])) {
                    result.Add(items[i]);
                }
            }
            return result;
        }

        static void Main()
        {
            var list = new List<int>() { 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 8 };

            list = RemoveDuplicatesSet(list);

            Console.WriteLine(string.Join(" ", list));
        }
    }
}


/*
run:
  
1 2 3 4 5 6 7 8
   
*/

 



answered Aug 27, 2018 by avibootz

Related questions

1 answer 184 views
4 answers 245 views
1 answer 222 views
1 answer 117 views
1 answer 155 views
1 answer 93 views
1 answer 87 views
...