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

  • SEARCH
  • Home
  • 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 961185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:18:10+00:00 2026-05-16T01:18:10+00:00

this is not a question as i think its discussion, i know you cant

  • 0

this is not a question as i think its discussion, i know you cant return an anonymous type across methods, when i first used anonymous types i thought it would be really nice to be able to return it across methods and when .net 4 came out and with the edition of the dynamic types i thought there might be a hope in returning an anonymous type through dynamic type like this:

      public static dynamic  getCustomer()
    {
        .....
        var x = from c in customers
                select new {Fname = c.FirstName};

        return x;
    }

and then

static void Main(string[] args)
    {
        dynamic x = getCustomer();
        Console.WriteLine(x.First().Fname);
        Console.ReadKey();
    }

but sadly that doesnt work although it compile good,

i guess the reason why is :

Anonymous types known in compile type and must be wrapped into classes that is KNOWN IN RUNTIME !, now anonymous type carry thier information in the compile time hoping some class will come and take this information to runtime , but dynamic type are unkown in compile time so passing anonymous type through dynamic type force the anonymous type to loss its informations/intellisence, i tried to debug and i could get the data i wanted but i guess it works only in debug mode , or maybe im missing something.

i was wondering if any one got it to work or thought about it ?

  • 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-05-16T01:18:11+00:00Added an answer on May 16, 2026 at 1:18 am

    You can return an anonymous type, you just can’t declare that you’ll do so. You can get round it with a horrible hack.

    The reason your code doesn’t work is nothing to do with anonymous types – it’s to do with extension methods not being found in dynamic typing.

    Change to:

    Console.WriteLine(Enumerable.First(x).Fname);
    

    and I expect it will work.

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

Sidebar

Related Questions

I will preface this question by saying, I do not think it is solvable.
This question might not seem programming related at first, but let me explain. I'm
I just want to clarify one thing. This is not a question on which
Okay this is not a question of how to get all uniques or How
No, this is not a question about generics. I have a Factory pattern with
This is not a technical question, but given that there are a few iPhone
Sorry for this not being a real question, but Sometime back i remember seeing
This question is not so much programming related as it is deployment related. I
This is not exactly a programming question, but it's highly related. We are writing
This is not a really technical question but is required for a system I

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.