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 179 views
1 answer 151 views
1 answer 112 views
3 answers 211 views
2 answers 211 views
2 answers 198 views
...