Distinct operator in Linq

Linq operator provides great flexibility and easy way of coding. Let’s again take one more example of distinct operator. As name suggest it will find the distinct elements from IEnumerable. Let’s take an example of array in console application and then we will again print array to see is it working or not. Below is the code for that. In this application I have integer array which contains duplicate elements and then I will apply distinct operator to this and then I will print again result of distinct operators to actually see whether its working or not.

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

namespace Experiment
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5 };
            var uniqueIntegers = intArray.Distinct();
            foreach (var uInteger in uniqueIntegers)
            {
                Console.WriteLine(uInteger);
            }
            Console.ReadKey();

        }
    }
}

Below is output as expected..

DisntictResult

That’s cool..Stay tuned for more.. Happy programming.

Technorati Tags: ,
Shout it
Published Sunday, January 09, 2011 1:11 AM by Jalpesh P. Vadgama
Filed under: , , ,

Comments

# re: Distinct operator in Linq

Saturday, January 08, 2011 3:21 PM by dumdum

Wow! now show us what orderby does!

# re: Distinct operator in Linq

Saturday, January 08, 2011 4:01 PM by Jalpesh P. Vadgama

@dumdum- This post is not for the people for who are masters of Linq. I have seen people writing routine for finding distinct values. This post is for all this kind of developers. For that I will certainly show what order by does.

# re: Distinct operator in Linq

Saturday, January 08, 2011 7:13 PM by HuntSoul

You again,you don't need to explain a lot,lol.But I do want you to explain,lol.I am a crazy English reader~

# India’s Best Travel Information Includes All Such Details About … | Global Travel Direction Blog

Pingback from  India’s Best Travel Information Includes All Such Details About … | Global Travel Direction Blog

# MS Visual Studio 2010 » Blog Archive » ???????????????? ????????????. 08.01.2011

Pingback from  MS Visual Studio 2010  » Blog Archive   » ???????????????? ????????????. 08.01.2011