python - Generating a List of object properties from a pre-existing list VB.Net -


with python background, i've become rather accustomed using lines like

print(" ".join({x.name x in my_list})) 

where

{x.name x in my_list} 

is list/array containing name property of each of objects in my_list.

i'm looking similar in vb.net, know possible using longer section of code like:

dim str1 = "" each item in mylist    str1 &= item.name & " " next 

but i'd prefer simpler solution i'll doing lot, , i've heard there's similar notation possible using linq.

any appreciated.

i think talking ienumerable(of t).select function. can use mapping collection of 1 type collection of type.

dim combinednames string = string.join(" ", mylist.select(function(item) item.name)) 

so equivalent python's {x.name x in my_list} in vb.net

dim names = mylist.select(function(item) item.name)  dim builder = new stringbuilder() each name in names     builder.append(name)     builder.append(" ") next  dim allnames = builder.tostring() 

notice select function return ienumerable(of t) type.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -