Re: How to access this static variable



Static members aren't what you want here. Read-only properties sound like a
better approach. You could try something like this (not tested):

public interface ILanguage
{
string Test { get; }
}

public class English : ILanguage
{
public string Test
{
get { return "test"; }
}
}

public class French : ILanguage
{
public string Test
{
get { return "le test"; }
}
}

A different approach might be:

public class Localization
{
private Dictionary<string, string> Strings;

static Localization(string lang)
{
// Load appropriate data into this.Strings from XML, SQL, etc.
}
}

You could then provide an indexer to access the values as follows:

Localization loc = new Localization("en");
loc["test"] // output would be "test"


"LamSoft" <[nospam]lamsoft@xxxxxxxxxxx> wrote in message
news:uefBMnUyHHA.4824@xxxxxxxxxxxxxxxxxxxxxxx
I am trying to make a language file and put all Static variables into each
different cs.
For example:


Class english : language{
public static string TEST = "test";
}

Class chinese : language {
public static string TEST = "´ú¸Õ";
}

Class language {}




and now i wanna access the TEST variable, but according to which language
is being selected ..

and I expected the following and something like that...

Language myLanguage = new english();
myLanguage.TEST // output will be "test"

Language myLanguage = new chinese();
myLanguage.TEST // output will be "´ú¸Õ"


Thank you very much.



"Patrice" <http://www.chez.com/scribe/> wrote in message
news:Ohwcf%23TyHHA.5484@xxxxxxxxxxxxxxxxxxxxxxx
You may want to explain what you are trying to do so that we can
understand why not using A.ABC is not something that fit your needs and
why accessing static members through an instance member would make sense.
It could raise alternate approach to the problem you are trying to
solve..

---
Patrice


"LamSoft" <[nospam]lamsoft@xxxxxxxxxxx> a écrit dans le message de news:
eFWxziTyHHA.1100@xxxxxxxxxxxxxxxxxxxxxxx
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









.



Relevant Pages

  • Re: Operator overloading in C
    ... All development of C as an independent language has ... making any changes or improvements to the standard ... The lack of a counted string data structure, ... Pointers can't be used for arg1 or arg2. ...
    (comp.std.c)
  • Re: syntax...
    ... B&D on the part of the language designer. ... probably handle concatenation of string literals by itself, ... bitwise XOR, or if not that, then exponentiation.) ...
    (comp.lang.misc)
  • Why C Is Not My Favourite Programming Language
    ... C has no string type. ... compiler take care of the rest. ... Why does any normal language ... the programmer fail. ...
    (comp.lang.c)
  • Re: How to access this static variable
    ... string Test ... public class English: ILanguage ... Class chinese: language { ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Controlling Javascript from server side
    ... but five different language implementations here. ... 'true' means that the request must be handled asynchronously. ... There is exactly *no* reason for such a thing here. ... | percent-endoded string). ...
    (comp.lang.javascript)