Take the 2-minute tour ×

I have a collection of custom objects, dependents. The custom object has about 70 properties. I want to extract just one property, the membernumber. I have the following code, where I am extracting the membernumbers and creating another list:

var memberIDs = (from d in dependents
                            select new
            foreach(var id in memberIDs)
                string idValue = id.ToString();

The problem is that idValue comes as "{ MemberNum = 20044782604 }" instead of just the "20044782604". Please let me know how to resolve it.


share|improve this question
Replaced string idValue = id.ToString(); with string idValue = id.MemberNum; –  user466663 Sep 12 '12 at 20:27
That's an unnecessarily complex solution. You should fix the problem at its origin, in the query, and not work around the symptoms when you enumerate. –  codesparkle Sep 12 '12 at 20:44
add comment

1 Answer

That's because you are creating a new anonymous type with the MemberNum as a property. Just select it instead.

var memberIDs = from d in dependents
                select d.MemberNum;

This will yield an IEnumerable<int> instead of an IEnumerable<AnonymousType> (assuming MemberNum is of type int).

share|improve this answer
add comment

Your Answer


