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,914 questions

51,847 answers

573 users

How to merge two List<int> and removing duplicate values in C#

1 Answer

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> list1 = new List<int> { 1, 13, 1, 13, 16 };
            List<int> list2 = new List<int> { 13, 1, 13, 2, 4, 6, 8 };

            List<int> list12 = list1.Union(list2).ToList();

            foreach (int n in list12)
                Console.WriteLine(n);
        }
    }
}

/*
run:
    
1
13
16
2
4
6
8
       
*/

 



answered Apr 23, 2017 by avibootz

Related questions

1 answer 165 views
1 answer 141 views
1 answer 101 views
2 answers 198 views
3 answers 184 views
2 answers 172 views
...