【发布时间】:2019-09-10 01:00:25
【问题描述】:
我有一个vector类,有两种解构方法如下:
public readonly struct Vector2
{
public readonly double X, Y;
...
public void Deconstruct( out double x, out double y )
{
x = this.X;
y = this.Y;
}
public void Deconstruct( out Vector2 unitVector, out double length )
{
length = this.Length;
unitVector = this / length;
}
}
我在其他地方:
Vector2 foo = ...
(Vector2 dir, double len) = foo;
这给了我:
CS0121: The call is ambiguous between the following methods or properties: 'Vector2.Deconstruct(out double, out double)' and 'Vector2.Deconstruct(out Vector2, out double)'
这怎么模棱两可?
编辑:手动调用解构可以正常工作:
foo.Deconstruct( out Vector2 dir, out double len );
【问题讨论】:
-
如果你的 Vector 类有隐式转换到/从双精度,那么这将是模棱两可的。