... in particular, the parameters in
( readonly ref
). Here is my situation:
I have a UWP project and a UWP Unit Test project in the same Visual Studio solution. Both projects focus on C # 7.2. The main UWP project has this class (pay attention to the parameters in
):
public struct Cell
{
public Cell(int x, int y)
{
X = x;
Y = y;
}
public int X { get; }
public int Y { get; }
public static Cell operator +(in Cell left, in Cell right)
{
return new Cell(left.X + right.X, left.Y + right.Y);
}
public static Cell operator -(in Cell left, in Cell right)
{
return new Cell(left.X - right.X, left.Y - right.Y);
}
public override string ToString() => $"{X}, {Y}";
}
When I use those statements from the UWP test project :
[TestMethod]
public void TestMethod1()
{
Cell cell1 = new Cell(0, 0);
Cell cell2 = new Cell(1, 1);
var added = cell1 + cell2 ;
var minus = cell1 - cell2 ;
}
I get:
UnitTest.cs(16,25,16,38): error CS0019: Operator '+' cannot be applied to operands of type 'Cell' and 'Cell'
UnitTest.cs(17,25,17,38): error CS0019: Operator '-' cannot be applied to operands of type 'Cell' and 'Cell'
However, the same use within the main UWP project does not produce compiler errors.
Why is this?
source
share