如何引用接口属性

时间:2019-02-15 14:39:25

标签: c# interface properties

我定义一个接口并构建一个继承它的类。

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()));

为什么?

0 个答案:

没有答案