I’m trying to call the getter of a static variable in another class. Can someone tell me why this works:
protected static SymTab _symTab;
public SymTab symTab
{
get{return _symTab;}
set{_symTab = value;}
}
and this does not:
public static SymTab symTab {get; protected set;}
The first version has an instance property which gets/sets a static variable.
The second version has a static property which gets/sets a static variable. (The setter is protected, too, but that doesn’t seem to be your immediate problem.)
I would strongly discourage the first form – instance properties should reflect something about that instance; you wouldn’t expect setting a property on one instance to change the property value for a different instance.
With the second form, you can just use:
instead of:
Additionally, I would note:
symTabviolates .NET naming conventionsSymTabisn’t as clear asSymbolTableor whatever that abbreviation is short forEDIT: Note that now we know it’s coming from Java, that explains the problem you’re seeing. In Java, it’s legal (but a bad idea) to refer to a static member “via” a variable or other expression. It makes for very confusing code though. For example:
That makes it look like you’re telling the new thread to sleep, but actually it’s a call to the static
Thread.sleepmethod which causes the current thread to sleep. Some Java IDEs will optionally flag this up as a warning or error.Fortunately, C# doesn’t allow this in the first place.