Solved

C# - manipulate list of objects

Posted on 2010-11-19
4
415 Views
Last Modified: 2013-12-17
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
0
Comment
Question by:JosephEricDavis
  • 3
4 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 34174057
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
 
LVL 22

Accepted Solution

by:
p_davis earned 500 total points
ID: 34174059
sorry, forgot the =

List<string> test =  tramsList.Select(tramsNSNList=> tramsNSNlist.Base4DPrimaryIdentifier).ToList();
0
 
LVL 7

Author Closing Comment

by:JosephEricDavis
ID: 34174158
This is actually exactly what I was looking for.  Thanks.
0
 
LVL 22

Expert Comment

by:p_davis
ID: 34174167
cool, not a problem. thanks for the grade.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now