?
Solved

C# - manipulate list of objects

Posted on 2010-11-19
4
Medium Priority
?
433 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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