c# - linq query group by in a list of strings -


this question has answer here:

i new linq query c#. have list of strings , new list or delete double strings.

list<string> zipcodes = new list<string>(); zipcodes.add("1234"); zipcodes.add("1234"); zipcodes.add("1234"); zipcodes.add("4321"); zipcodes.add("4321");  list<string> groupbyzipcodes = (from zip in zipcodes group zip zip newgroup select newgroup.tolist()); 

cannot implicitly convert type 'system.collection.generic.ienumarable<system.collections.generic.list<string>' 'system.collections.generic.list<string>. explicit conversion exists (are missing cast?)

you can use distinct keyword in linq:

var dedupedlist = zipcodes.distinct().tolist(); 

for more see https://msdn.microsoft.com/en-us/library/vstudio/bb348436(v=vs.100).aspx


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -