-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Revised (in)equality operator articles #9596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
closing and reopening to build with new snippets |
BillWagner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this is much improved @pkulikov The language is more clear and easier to understand.
I had one comment to address, and then this is ready to merge. I don't think we need a new sample for an enum comparison. I think it would be enough to say that == and != for enum types obey the same rules as the underlying integral type.
|
|
||
| [!code-csharp-interactive[value types equality](~/samples/snippets/csharp/language-reference/operators/EqualityAndNonEqualityExamples.cs#ValueTypesEquality)] | ||
|
|
||
| By default, the `==` operator is not defined for a user-defined [struct](../keywords/struct.md) type. A user-defined type can [overload](#operator-overloadability) the `==` operator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should state that == is defined for enum types. That slipped through the cracks in the new (more clear) description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BillWagner indeed, as behavior for structs is described, enum case also should be stated explicitly. Thank you for the remark. I've added the clarification, please check the latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pkulikov I'll suggest this small word change:
"Two operands of the same enum type are equal if the ..."
It's a small change, but the text you have could be misinterpreted to support something like the following:
enum Color
{
Red,
Green,
Blue
}
enum Status
{
Red,
Yellow,
Green
}
// compare two enum operands:
bool equal = (Status.Red == Color.Red); // CS0019 (operator == cannot be applied to ...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BillWagner that's a good catch! Thanks. Fixed.
|
Thanks @pkulikov This looks great. I'll |
Snippets are moved to the samples repo: dotnet/samples#512