Re: How to access this static variable
- From: "LamSoft" <[nospam]lamsoft@xxxxxxxxxxx>
- Date: Wed, 18 Jul 2007 20:39:33 +0800
But there are not only 1 static variable in Class A, .... i don't wanna make
every function for each static variable
"Hans Kesting" <news.2.hansdk@xxxxxxxxxxxxxxx> wrote in message
news:c04e80a71b5bb8c9975e161250ae@xxxxxxxxxxxxxxxxxxxxx
Class B { public B() {} }
Class A : B {
public static string ABC = "myABC";
public A() {}
}
main Program:
B myObject = new A();
and now is it possible to access "ABC" through "myObject" without
modifying the source code in Class A and Class B.
Thanks
As it's a static variable (in type A), you can only access it through the
Type A:
A.ABC, not through an instance.
Type B doesn't know anything about things declared in derived types (like
A),
so your myObject (which is "just a B") doesn't know anything about that
ABC.
*if* B declares a (virtual) method:
public virtual string MyMethod() { return "nil"; }
and A overrides it:
public override string MyMethod() { return A.ABC; }
then your myObject can still access the contents of ABC, using this
MyMethod()
Hans Kesting
.
- Follow-Ups:
- Re: How to access this static variable
- From: Patrice
- Re: How to access this static variable
- References:
- How to access this static variable
- From: LamSoft
- Re: How to access this static variable
- From: Hans Kesting
- How to access this static variable
- Prev by Date: validate CheckboxList
- Next by Date: Re: Are there any issues with installing PHP along with ASP.NET?
- Previous by thread: Re: How to access this static variable
- Next by thread: Re: How to access this static variable
- Index(es):
Relevant Pages
|