Set Operators-Distinct


The Distinct operator eliminates duplicate elements from a sequence.


The example creates a sequence of unique factors of 300 by using the Distinct method on the integer array of factors to remove duplicates.











using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication4

{

class Program

{

  static void Main(string[] args)

   {

    int[] factorsOf300 = { 2, 2, 3, 5, 5 };


    var uniqueFactors = factorsOf300.Distinct();


    Console.WriteLine("Prime factors of 300:");

    foreach (var f in uniqueFactors)

    {

     Console.WriteLine(f);

    }

    Console.ReadLine();

    }

  }

}



Output:


                    

Aspnet Related Tutorials

...more

New Aspnet Resources

...more

Copyright © 2013 VisualBuilder. All rights reserved