I was reading this page, which is officially referenced in the release notes of Visual Studio 17 RC, it states the following:
For the purpose of Overloading Overriding Hiding, tuples of the same types and lengths as well as their underlying ValueTuple types are considered equivalent. All other differences are immaterial.
When overriding a member it is permitted to use tuple types with same or different field names than in the base member.
A situation where same field names are used for non-matching fields between base and derived member signatures, a warning is reported by the compiler
When giving that a shot:
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, string d))': cannot change tuple element names when overriding inherited member 'Foo.AbstractTuple((int a, string b))'
and
Error CS8139 'Bar.OverrideTuple((int c, string d))': cannot change tuple element names when overriding inherited member 'Foo.OverrideTuple((int a, string b))'
The Questions are:
Is the official design Notes wrong ? Or is this a behavior that is yet to be implemented in the official C# 7.0 Release ?
If this is the correct behavior, does it make sense that the tuple Field Names has to be the same in the overridden method ? Keeping in mind that two methods with same Tuples
(int a, int b)and(int c, int d)are not considered overload candidates and generate an error!Do we have official C# 7.0 Features documentation somewhere ?
System.ValueTuple.