vb.net - Distinct List(Of String) from two Lists -


i have 2 list(of string) named methodcodes , methoddescriptions. create unique values.

e.g. have these values in lists...

methodcodes (45, 45, 46a, 46b, 47, 47)

methoddescriptions (meth45, meth45, meth46, meth46, meth47, meth47)

i need reduce lists this...

methodcodes (45, 46a, 46b, 47)

methoddescriptions (meth45, meth46, meth46, meth47)

actually, unique must values in methodcodes list, count of items must same in both lists.

tomas

if values in these 2 list have association better idea keep them associated in appropriate data structure such class.

a simple class it:

private class method     public property code string     public property description string     public sub new(code string, description string)         me.code = code         me.description = description     end sub end class 

this allows add values this:

dim methods new list(of method) methods.add(new method("45", "meth45")) methods.add(new method("45", "meth45")) methods.add(new method("46a", "meth46")) methods.add(new method("46b", "meth46")) methods.add(new method("47", "meth47")) methods.add(new method("47", "meth47")) 

and find distinct code values , associated descriptions this:

for each distinctmethod in methods.distinct.groupby(function(x) x.code).select(function(d) d.first()).tolist()     debug.writeline(distinctmethod.code & "-" & distinctmethod.description) next 

output:

45-meth45 46a-meth46 46b-meth46 47-meth47 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -