Get the number of distinct property values in List<T> using LINQ in C# -


in list list<myclass> listofmyclasses, how can 1 how many distinct groupid property values there using linq?

public class myclass {      public int groupid; } 

for example let's have list:

listofmyclasses: {myclass1 (groupid = 1), myclass2 (groupid = 3), myclass3 (groupid = 1)} 

here should result 2 (two distinct numbers groupid).

here 1 way using distinct:

listofmyclasses.select(t => t.groupid).distinct().count() 

or can use groupby:

listofmyclasses.groupby(t => t.groupid).count() 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo