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
LVL 7
JosephEricDavisAsked:
Who is Participating?
 
p_davisConnect With a Mentor Commented:
sorry, forgot the =

List<string> test =  tramsList.Select(tramsNSNList=> tramsNSNlist.Base4DPrimaryIdentifier).ToList();
0
 
p_davisCommented:
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();
0
 
JosephEricDavisAuthor Commented:
This is actually exactly what I was looking for.  Thanks.
0
 
p_davisCommented:
cool, not a problem. thanks for the grade.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.