c# - Get a new result from a List -


i have detailed list , want new 1 elements of 1 property no duplicates this.

list<class1> list = list<class1>(); list.add(new class1("1", "walmart", 13.54)); list.add(new class1("2", "target", 12.54)); list.add(new class1("3", "walmart", 14.54)); list.add(new class1("4", "bestbuy", 16.54)); list.add(new class1("5", "walmart", 19.54)); list.add(new class1("6", "amazon", 12.33)); 

my new list

list<stores> newlist = list.select / findall / group ? 

i want collection

newlist = "walmart", "target", "bestbuy", "amazon" 

you need distinct , select.

var newlist = list.select(x => x.name).distinct().tolist(); 

if want original class, have bit more fancy.

either morelinq , use distinctby method:

var newlist = list.distinctby(x => x.name).tolist(); 

or use clever groupby hack:

var newlist = list.groupby(x => x.name).select(x => x.first()); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -