Open jahbenjah opened 4 years ago
Hi @jahbenjah,
The order matters. In fact, with a different order - they are considered different types. With the example above, p3
is a different anonymous type from p1
and p2
- as they are initialized in a different order.
Within the same program, two anonymous object initializers that specify a sequence of properties of the same names and compile-time types in the same order will produce instances of the same anonymous type.
Hi @IEvangelist
sorry, i update my question. I think this phrase "so that two instances of the same anonymous type are equal if and only if all their properties are equal" must include the order of properties.
Hi @IEvangelist
sorry, i update my question. I think this phrase "so that two instances of the same anonymous type are equal if and only if all their properties are equal" must include the order of properties.
Ah, ok. I see what you're saying now. So the statement would need to be updated to include order.
The Equals and GetHashcode methods on anonymous types override the methods inherited from object, and are defined in terms of the Equals and GetHashcode of the properties, so that two instances of the same anonymous type are equal if and only if all their properties are equal and initialized in the same order.
We'll happily review a pull request, I've updated this issue and marked it as "up for grabs" - thank you.
I'm removing the up-for-grabs label (for now at least)
The ECMA standards committee is currently working on a plan to to update the spec and the standard. We'll be surfacing that soon.
I think the spec is correct as is. Since p1
and p3
are not instances of the same anonymous type, there is no reason to add the additional clause to the spec.
@svick I agree that no additional clause is needed.
The example is informative text, and it may be worth adding an equality example as well as the assignment example.
This issue has been closed as part of the issue backlog grooming process outlined in dotnet/docs#22351.
That automated process may have closed some issues that should be addressed. If you think this is one of them, reopen it with a comment explaining why. Tag the @dotnet/docs
team for visibility.
@BillWagner Do you still think it might be worth updating the example in the spec? If you do, you should probably reopen this issue.
reopening to reassign to the committee for review.
@jskeet
This may be below the bar. The "in the same order" is already in informative text for assignment, but not for equality.
I think we probably do want to improve this, but I'm happy to close it as a duplicate of #114.
Labeling as "meeting:discuss" and "meeting:proposal" to ratify that decision.
Revisiting this many moons later - I still want to close this as a duplicate of #114. I'm re-adding "meeting: discuss" to make it easier to find in our meeting.
two anonymous objects with the same Properties in different order should be equal ?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.