How to find distinct element from multiple time's coming elements in the Array in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FromMultipleElementsFindDistinctEach
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] ar = new int [] {1,1,1,2,2,2,2,2,3,4,4};
            var distinct = new HashSet<int>(ar);
            foreach (int i in distinct)
            {
                Console.Write(i+",");
            }
            Console.Read();
        }
    }
}

Share:

No comments:

Post a Comment

Monday, 31 August 2015

How to find distinct element from multiple time's coming elements in the Array in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FromMultipleElementsFindDistinctEach
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] ar = new int [] {1,1,1,2,2,2,2,2,3,4,4};
            var distinct = new HashSet<int>(ar);
            foreach (int i in distinct)
            {
                Console.Write(i+",");
            }
            Console.Read();
        }
    }
}

No comments:

Post a Comment

Popular

Total Pageviews

Archive