Solved

C# - manipulate list of objects

Posted on 2010-11-19
4
419 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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