Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8927783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:17:26+00:00 2026-06-15T08:17:26+00:00

Possible Duplicate: How can I pass an anonymous type to a method? I want

  • 0

Possible Duplicate:
How can I pass an anonymous type to a method?

I want to pass the collection of LINQ result to another method

This is the LinQ code

var sets =
        from a in patient
        from b in patient
        from c in patient
        from d in patient
        from l in patient
        where a.VisitNum < b.VisitNum && b.VisitNum < c.VisitNum && c.VisitNum < d.VisitNum && d.VisitNum < l.VisitNum
        select new { a, b, c, d, l };

The query present the result like this “combinations”

   ID    Visit DAte       Visit number    Rational 
    -------------------------------------------------
   a- 1     14/05/2011           1           new
   b- 1     15/06/2012           2           Emergency 
   c- 1     17/07/2012           3           Check-Up

   a- 1     14/05/2011           1           new
   b- 1     15/06/2012           2           Emergency 
   c- 1     18/12/2012           5           Check-Up
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:17:27+00:00Added an answer on June 15, 2026 at 8:17 am

    new { a, b, c, d, l } creates an item of anonymous type so return value of entire LINQ query results in an anonymous type as well. To pass such value in a method I would suggest converting it to a known type. Just introduce a new class and an interface if you would like abstract a method from a concrete implementation:

    It is not clear what query does and which item types are so update class and type names accordingly:

    interface IResultSet
    {
       TypeA A { get; }
       TypeB B { get; }
       TypeC C { get; }
       TypeD D { get; }
       TypeL L { get; }
    }
    
    class ResultSet : IResultSet
    {
       public ResultSet(inject all property values here) {}
    
       public TypeA A { get; private set; }
       public TypeB B { get; private set; }
       public TypeC C { get; private set; }
       public TypeD D { get; private set; }
       public TypeL L { get; private set; }
    }
    
    IEnumerable<IResultSet> sets =
        from a in patient
        from b in patient
        from c in patient
        from d in patient
        from l in patient
        where a.VisitNum < b.VisitNum 
              && b.VisitNum < c.VisitNum 
              && c.VisitNum < d.VisitNum 
              && d.VisitNum < l.VisitNum
        select new ResultSet(a, b, c, d, l);
    

    And keep in mind that LINQ Select() has deffered execution so query itself will not be executed until you access result set enumeration, so if you need to execute it immediately just add .ToList() call at the query end:

    Deffered:

    ProcessData(sets);
    

    Immediate execution:

    ProcessData(sets.ToList());
    
    // Now you can pass results in a method like this
    public void ProcessData(IEnumerable<IResultSet> items)
    

    And finally I would suggest NOT using dynamic type to abstract such anonymous types, you can use it but in some special cases so it would be adequate decision. In your case it will makes code less readable and broke type safety, dynamic perfectly fits for DSL engines and things to handle dynamic structure data but not to be a silver bullet for those who badly know OOP basics.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I pass an anonymous type to a method? Im trying
Possible Duplicate: JavaScript Pass Variables Through Reference How can you do something like this
Possible Duplicate: Dynamic LINQ OrderBy How can I pass a value to an OrderBy
Possible Duplicate: Can I pass an array as arguments to a method with variable
Possible Duplicate: Can I pass constructor parameters to Unity’s Resolve() method? Constructor Injection in
Possible Duplicate: How can I pass a parameter to a setTimeout() callback? Is there
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Can you animate a height change on a UITableViewCell when selected? This
Possible Duplicate: Can't pass mysqli connection in session in php Many of us have
Possible Duplicate: How can I pass command-line arguments in IronPython? I am new to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.