Generic methods with anonymous types

suggest change

Generic methods allow the use of anonymous types through type inference.

void Log<T>(T obj) {
    // ...
}
Log(new { Value = 10 });

This means LINQ expressions can be used with anonymous types:

var products = new[] {
    new { Amount = 10, Id = 0 },
    new { Amount = 20, Id = 1 },
    new { Amount = 15, Id = 2 }
};
var idsByAmount = products.OrderBy(x => x.Amount).Select(x => x.Id);
// idsByAmount: 0, 2, 1

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents