I read this page , which is officially mentioned in the release notes in Visual Studio 17 RC, it states the following:
For the purpose of overloading Overriding Hiding tuples of the same type and length, as well as their basic types, ValueTuple is considered equivalent. All other differences are not significant.
When redefining a member, it is allowed to use tuple types with the same or different field names than in the base element.
The situation when the same field names are used for mismatched fields between the base and derived signatures of participants, a warning is reported to the compiler
When creating this snapshot:
public abstract class Foo { public abstract void AbstractTuple((int a, string b) tuple); public virtual void OverrideTuple((int a, string b) tuple) { Console.WriteLine($"First= {tuple.a} Second = {tuple.b}"); } } public class Bar : Foo { public override void AbstractTuple((int c, string d) tuple) { Console.WriteLine($"First= {tuple.c} Second= {tuple.d}"); } public override void OverrideTuple((int c, string d) tuple) { base.OverrideTuple(tuple); } }
I get the following errors:
Error CS8139 'Bar.AbstractTuple ((int c, line d))': tuple element names cannot change when overriding the inherited member 'Foo.AbstractTuple ((int a, line b))'
and
Error CS8139 'Bar.OverrideTuple ((int c, line d))': tuple element names cannot be changed when overriding the inherited member 'Foo.OverrideTuple ((int a, line b))'
Questions:
Is the official design error incorrect? Or is this behavior that has yet to be implemented in the official version of C # 7.0?
If this is the correct behavior, does it make sense that the root field names should be the same in the overridden method? Bearing in mind that two methods with the same Tuples (int a, int b)
and (int c, int d)
not considered overloaded candidates and generate an error!
Do we have official documentation on C # 7.0 features?
source share