我有一個列表,它包含'Reference'類作爲泛型類型。所以,我應該能夠填補我的名單與「參考」類的子類,但是編譯器報錯:編譯錯誤:Property not recognized
'naturalCalc.Enginee.Reference'
does not contain a definition for'Opener'
and no extension method'Opener'
accepting a first argument of type'naturalCalc.Enginee.Reference'
could be found (are you missing a using directive or an assembly reference?) (CS1061)ToPostfix.cs:27,34
在「ToPostfix」類撥碼開關確保項目具有「開瓶器」屬性在第二種情況下。
// The 'MyBrackets' class which contains the 'Opener' property.
public class MyBrackets : naturalCalc.Enginee.Reference
{
private bool opener;
public MyBrackets(bool opener)
{
this.opener = opener;
}
public bool Opener { get { return this.Opener; } }
}
// The 'ToPostfix' class in which the error is taken place.
class ToPostfix
{
List<Reference> infix = new List<Reference>();
List<Reference> postfix = new List<Reference>();
public ToPostfix(List<Reference> infixForm)
{
this.infix = infixForm;
foreach (Reference item in this.infix)
{
switch (item.ToString())
{
case "naturalCalc.Enginee.MyFloat":
this.postfix.Add(item);
break;
case "naturalCalc.Enginee.MyBrackets":
if (item.Opener)
{
this.postfix.Add(item);
}
break;
}
}
}
}
OP在'get'中只需要一個小寫的'opener'。 'public bool Opener {get {return this.opener; }}' – 2012-07-15 17:08:37
@Kevin是的,那就夠了=) – 2012-07-15 17:09:50