Why does the Equals implementation for anonymous types compare fields?

Anonymous type instances are immutable data values without behavior or identity. It doesn’t make much sense to reference-compare them. In that context I think it is entirely reasonable to generate structural equality comparisons for them. If you want to switch the comparison behavior to something custom (reference comparison or case-insensitivity) you can use Resharper to … Read more

How to get index using LINQ? [duplicate]

myCars.Select((v, i) => new {car = v, index = i}).First(myCondition).index; or the slightly shorter myCars.Select((car, index) => new {car, index}).First(myCondition).index; or the slightly shorter shorter myCars.Select((car, index) => (car, index)).First(myCondition).index;