Count - Simple

Query
public void Linq73()
{
int[] factorsOf300 = { 2, 2, 3, 5, 5 };

int uniqueFactors = factorsOf300.Distinct().Count();

Console.WriteLine("There are {0} unique factors of 300.", uniqueFactors);
}
Lambda Expression
public void Linq73()
{
int[] primeFactorsOf300 = { 2, 2, 3, 5, 5 };

int uniqueFactors = primeFactorsOf300.Distinct().Count();

Console.WriteLine("There are {0} unique prime factors of 300.", uniqueFactors);
}
Output
There are 3 unique factors of 300.
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +