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

python - jinja2: TemplateSyntaxError: expected token ',', got 'string' -

Qt4: how to send QString inside a struct via QSharedMemory -

node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -