var query = from c in customers
join o in orders on c.ID equals o.ID
select new { c.ID, c.City, SalesBefore = c.Sales, NewOrder = o.Amount, SalesAfter = c.Sales + o.Amount };
foreach (var item in query)
{
Console.WriteLine(item);
}
I was running above code in console application. When it generates the result, it is displayed in the {}. Why is the result in the {}?
Example result
{ ID=1, City=New York.....}
There is nothing crucial. Just curious to know.
That's just the default .ToString implementation of anonymous types. Nothing more or less.
That code uses the Console.WriteLine(object) overload, which under the hood calls the .ToString() method on the object given. The .ToString() method, in turn, renders an anonymous type in that way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With