LINQ not giving me output I want (newbie question)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: LINQ not giving me output I want (newbie question)

  1. #1
    Join Date
    Jun 2010

    LINQ not giving me output I want (newbie question)

    For this example I have a Man object. A property of the Man object is a generic list of Dog objects. Each Dog object also has a generic list of just strings.

    I am grabbing a property from the main object, Man and then digging down into the Man object's associated Dog list to grab the bones property of each Dog object in that list. However, when ever I print to console I keep on getting this (the number of bones (property) is never being printed:

    1st example


    Name: Josh

    Bones: System.Linq.Enumerable+WhereSelectListIterator'2[Dog, System.Int32]

    var allMen =
    from man in lstMan
    select new
    manname =,
    bonenum = man.dogs.Select(p=>p.bones)

    2nd example

    This also occurs in this example where I'm using Group By:

    var registeredMen =
    from man in lstMan
    group man by into mangrp
    select new
    studen = mangrp.Key,
    vals = mangrp.SelectMany(p=>p.listofStrings)





    Can anyone tell me what I'm doing wrong in each example?

  2. #2
    Join Date
    Oct 2007
    Fredericksburg, VA

    Re: LINQ not giving me output I want (newbie question)

    Just to clarify here, your Man object has multiple Dogs, and each Dog object, has an integer property that has the number of bones, and you want to get this property, sum it up from all the Dog's for each Man, and display it using LINQ?

    If you create a dummy console project and attach the source or put it on pastebin (, I'll take a look and see what I can to do to help.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center