c# - LINQ Basics, How do I do a groupby and get a string at the end? -


hello have class so

class myclass {     public string string1;     public string string2;     public string string3; } 

and have list of them , want produce list of strings of unique string1 s.

list<myclass> myinstance = getinstanceofmyclass();  methodthatrequireslistofstrings( myinstance.groupby(p => ??????? .tolist<string>()); 

what replace ??????? ?

i can't believe i've gone long without doing group lambda expression...

in case, not use grouping @ all. if want distinct string1 values, use distinct().

myinstance.select(obj => obj.string1).distinct(); // .tolist() 

if want learn how group, consider

myinstance.groupby(obj => obj.string1).select(grp => grp.key); // .tolist() 

however, again, go first option.


Comments

Popular posts from this blog

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

apache - Add omitted ? to URLs -

php - How can I stop spam on my custom forum/blog? -