-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
[Question/Proposal] Support for == and != on ValueTuple #13155
Comments
I agree, I think that the compiler should compare the elements in the tuples directly to one another as if there is no tuple: (Foo, Bar) tuple1 = ...;
(Foo, Bar) tuple2 = ...;
if (tuple1 == tuple2) { ... }
// equivalent to writing:
if (tuple1.Item1 == tuple2.Item1 && tuple1.Item2 == tuple2.Item2) { ... } That way, as mentioned, the compiler can take advantage of overloading equality operators as well as implicit conversions. Assuming that Roslyn goes in that direction, how would it compare two tuples where the named elements are in different order but would otherwise be the same? var tuple1 = (first: "John", last: "Smith");
var tuple2 = (last: "Smith", first: "John");
bool equals = (tuple1 == tuple2); // ? |
@HaloFour I think names are just for convenience. Tuples, by definition, are just some ordered values. So I'd say that names shouldn't affect equality etc. |
Adding support for the operators Select Case (ch, nx)
Case ((True, "{"c), (True, "{"c))
' Escaped Opening Brace
Case ((True, "}"c), (True, "}"c))
' Escaped Closing Brace
End Select Edit: It feels very natural fit for VB.net (at least) |
One scenario was mentioned in LDM about this: (T, int) tuple = M();
if (t == (null, 0)) ...; // there is some target-typing happening here for null We'd want this to work, since the same code without tuples works: |
I'll close this issue from the compiler repo. The discussion was moved to csharplang repo: dotnet/csharplang#190 |
Following this PR: dotnet/corefx#10417
And these issues: https://github.com/dotnet/corefx/issues/10416, dotnet/corefx#10417
It seemed like support for
==
and!=
onValueTuple
might be needed. I don't know if the compiler already supports this ?If not @gafter mentioned support for this should be in the compiler not in corefx.
The text was updated successfully, but these errors were encountered: