我定义一个接口并构建一个继承它的类。
interface IOperator
{
int Priority{ get; }
string Identifier { get; }
int Dimension { get; }
Expression GetExpression(IVariable[] variables);
object Excute(IVariable[] variables);
}
public class Op_Muti:IOperator
{
int IOperator.Priority { get { return 40; } }
string IOperator.Identifier { get { return "*"; } }
int IOperator.Dimension { get { return 2; } }
public object IOperator.Excute(IVariable[] variables)
{
throw new ArgumentOutOfRangeException(string.Format("{0} can't apply to {1}", Identifier, variables[0].VarType.ToString()));
}
}
标识符是在界面
中定义的string Identifier { get; }
并在Op_Muti类中实现
string IOperator.Identifier { get { return "*"; } }
但不能在
中引用throw new ArgumentOutOfRangeException(string.Format("{0} can't apply to {1}", Identifier, variables[0].VarType.ToString()));
为什么?