wpf - C# Group results from List into another List with selected fields -



wpf - C# Group results from List<T> into another List<T2> with selected fields -

i wondering if there's simpler way using linq or other way...

i want extract, list, rows, grouping them particular field , storing result in different, list containing grouped, not repeated, result of search parameter.

here's example:

public class customobj { public int doc { get; set; } public string desc { get; set; } public string name{ get; set; } } public class worker() { public void dowork() { list<customobj> objs = new list<customobj>(); objs.add(new customobj(1, "type1", "name1")); objs.add(new customobj(1, "type2", "name1")); objs.add(new customobj(2, "type2", "name2")); objs.add(new customobj(3, "type1", "name1")); objs.add(new customobj(3, "type2", "name1")); objs.add(new customobj(3, "type3", "name1")); // here's i'd // note not right formated function list<int> docs = objs.groupby(o => o.doc).select(o => o.doc).tolist<int>(); } }

at end docs list should this

docs[0] = 1 docs[1] = 2 docs[2] = 3

in current project have, far, 10 different objects, , i'm going have of them. of course of study i'd avoid writing extensive functions each one.

so if there's no other way @ to the lowest degree know.

thanks

what about:

list<int> docs = objs.select(o => o.doc).distinct().tolist();

c# wpf linq

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -