Click here to Skip to main content
16,004,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to return an Linq query Result Which is Stored in Var. How to Return it. I also googled.But Can't find an suitable answer.Any help is appreciated.
Posted
Updated 28-Jan-13 19:57pm
v5

 
Share this answer
 
Comments
Member 9626721 29-Jan-13 2:23am    
Thanks for Reply,But this link does not help me.i Want to return this anonymous type from a Method
You cannot type any method in C# to be the explicit type of an anonymous types. They cannot be "named" so to speak and hence cannot appear in metadata signatures.

If you really want to return a value which is an anonymous type there are 2 options

Have the return type of the method be System.Object. You can then do evil casting hacks to get a typed value in another method. This is very fragile and I don't recommend it.
Use a generic method and a type inference trick to get the return type correct. This would require a very interesting signature definition for your approach.
Anonymous types were not really meant to be passed around in this fashion. At the point you need to pass them around between your functions in this manner, you're better off explicitly defining a type.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900