Useful tip to infer types in Visual Studio.

There are times when your linq query would return complex data. If you are not exactly sure what the return type is, than simply assign the result to var and hover over the var to see its exact type. Here are two examples that illustrates the beauty.

image

In the above code, I have a complex anonymous type which consist of Name, Address and collection of orders.  I have another inferred type that is assigned by the query. If by looking at the query you cannot figure out the type, you always however over the type to see its actual type as shown below.

image

from the above capture, you would notice a popup that shows the type generated by the inferred type. When you move the mouse over the type that is assigned to query this is the result.

image

No Comments