Reputation: 47
How do I get the value of a static property from an instance of a class? see example below...
abstract class A {
public static double Foo {get; protected set;}
}
class B : A {
static B(){
Foo = 1;
}
}
class C : A {
static C(){
Food = 2;
}
}
class Test {
A test = new B();
//How do I get test.Foo ??
}
Upvotes: 0
Views: 121
Reputation: 14750
Static members (fields, properties, methods, etc.) are accessed via class name.
var x = A.Foo;
I think you are getting statics wrong.
Did you mean something like this?
abstract class A {
public double Foo {get; protected set;}
}
class B : A {
public B(){
Foo = 1;
}
}
class C : A {
public C(){
Foo = 2;
}
}
class Test {
A test = new B();
var foo = test.Foo;
}
Upvotes: 1