Given the interface definition and it's implementation:
public interface IArithmetic
{
int Summation { get; }
void Add(int x, int y);
}
public class Calculator : IArithmetic
{
public int Summation { get; private set; }
void IArithmetic.Add(int x, int y)
{
Summation = x + y;
}
}
A syntax error occurs when the implementation of Summation
is made explicit
public class CalculatorB : IArithmetic
{
// error: "private set;"
int IArithmetic.Summation { get; private set; }
void IArithmetic.Add(int x, int y)
{
Summation = x + y;
}
}
The accessibility modifier of 'CalculatorB.IArithmetic.Summation.set' accessor must be more restrictive than the property or indexer 'CalculatorB.IArithmetic.Summation'
Is there an accessor more restrictive than private? I'm not sure what the problem is here??
Below the set
accessor is modified (no pun) to fix CalculatorB
's syntax error.
public interface IArithmetic2
{
int Summation { get; set; }
void Add(int x, int y);
}
public class Calculator2 : IArithmetic2
{
int IArithmetic2.Summation { get; set; }
void IArithmetic2.Add(int x, int y)
{
// syntax error
Summation = x + y;
}
}
The name 'Summation' does not exist in the current context.
I'm not sure what causes this resulting syntax error?