Skip to content
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

Add == and != operators to ValueTuple.cs #17954

Closed
OzieGamma opened this issue Jul 29, 2016 · 1 comment
Closed

Add == and != operators to ValueTuple.cs #17954

OzieGamma opened this issue Jul 29, 2016 · 1 comment
Assignees
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation
Milestone

Comments

@OzieGamma
Copy link

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))
{
    // ...
}
@OzieGamma
Copy link
Author

It makes little sense to add these in the CoreFX. (See dotnet/corefx#10417).

I moved the issue to the Roslyn Repo. (dotnet/roslyn#13155)

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 1.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation
Projects
None yet
Development

No branches or pull requests

3 participants