-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementation
Milestone
Description
After the following discussion on https://github.com/dotnet/coreclr/issues/6520#issuecomment-236152874 we discovered ValueTuple did not implement the == and != operators.
I think this is an oversight, it looks pretty natural to me to write:
(name, age) = GetPersonTuple();
if ((name, age) == ("Jhon", 13))
{
// ...
}OR
tuple = GetPersonTuple();
if (tuple == ("Jhon", 13))
{
// ...
}Personally, I think that if the performance cost is not too high I might even compare variables using the tuple notation. It is easier to understand and to read than the && syntax:
var age = AskAge();
var name = AskName();
if((age, name) == (17, "Jhon"))
{
// ...
}instead of:
var age = AskAge();
var name = AskName();
if(age == 17 && name == "Jhon")
{
// ...
}This might overlap with the Tuple Patterns but I think those were removed from C# 7. Having to call .Equals seems very ugly to me.
tuple = GetPersonTuple();
if (tuple is ("Jhon", 13))
{
// ...
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementation