CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2010
    Posts
    1

    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

    Output:

    Name: Josh

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



    var allMen =
    from man in lstMan
    select new
    {
    manname = man.name,
    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 man.name into mangrp
    select new
    {
    studen = mangrp.Key,
    vals = mangrp.SelectMany(p=>p.listofStrings)

    };


    Output:

    Jake

    System.Linq.Enumerable+<SelectManyIterator>d__14'2[Course,System.String]


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

  2. #2
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    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 (http://pastebin.com/), 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
  •  





Click Here to Expand Forum to Full Width

Featured