Link to home
Start Free TrialLog in
Avatar of JosephEricDavis
JosephEricDavis

asked on

C# - manipulate list of objects

I have a list object

List<TramsResourceCatalog> tramsList

One of the data members of TramsResourceCatalog is string PrimaryIdentifier

What is the easiest way of transforming my List<TramsResourceCatalog> into only being a list of the one property PrimaryIdentify, ie a List<string> of PrimaryIdentify.

What I'm currently doing is...

List<TramsResourceCatalog> tramsList = ScheduleService.GetTramsResourceCatalogList();
                List<string> test = (from tramsNSNlist in tramsList select tramsNSNlist.Base4DPrimaryIdentifier).ToList();

But I think there must be an easier more simplistic way to do this that I'm just not familiar with.

Thanks
Avatar of p_davis
p_davis

still using linq// i don't think your current solution is too complicated - pretty clear cut to me.

List<string> test tramsList.Select(tramsNSNList=> tramsNSNlist.Base4DPrimaryIdentifier).ToList();
ASKER CERTIFIED SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JosephEricDavis

ASKER

This is actually exactly what I was looking for.  Thanks.
cool, not a problem. thanks for the grade.