.net - code writing optimisation -


i have class person, id, name, salary properties.

class person     friend id long     friend name string     friend salary decimal end class 

i wan't make list of salaries.

dim plist new list(of person) 

plist loaded 50 entries

dim salarylist new list(of decimal) each p person in plist     salarylist.add(p.salary) next 

ok, works. there way :

dim salarylist list(of decimal) = plist(each).salary 

you can use select projection:

dim salarylist = plist.select(function(p) p.salary).tolist() 

or

dim salarylist = p in plist                  select p.salary 

note later returns query (ienumerable(of decimal)) , not list. if need list, call tolist() on query, not necessary.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -