Re: Override static derived variable



"knocte" <knocte@xxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le message de news:
d93v33$skl$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

> I have a problem with C# language. I want to define an algorithm on a
> static function inside an abstract class. This function calls a static
> variable inside the same class. Then I want to define some derived
> classes wich inherit the function and override the variable, but it
> doesn't work.

I would have said that you should not override the variable, just the
initialising code in a static constructor.

abstract public class X
{
protected static string var;

protected static SetVar(string value)
{
var = value;
}

static X()
{
SetVar("X");
}

public static void print_my_var()
{
Console.WriteLine("my var is " + var);
}
}

public class A : X
{
static A()
{
SetVar("A");
}

But this doesn't work either as it appears that the only static constructor
to be called in class A is X().

I must admit that this is not as I would have expected. Does anyone know if
this is a bug in beta 1 ?

Joanna

--
Joanna Carter
Consultant Software Engineer


.



Relevant Pages

  • Re: Generic inheritance
    ... I have also a generic collection class with this class header definition. ... is constraned to be or inherit from Animal." ... public abstract class Animal {. ... public class Chicken: Animal ...
    (microsoft.public.dotnet.languages.csharp)
  • Generic inheritance
    ... I have also a generic collection class with this class header definition. ... public abstract class Animal {. ... public class Chicken: Animal ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Factory Pattern Appropriate?
    ... public class WidgetContext_Container: WidgetContext { ... > The factory basically needs to choose between 20 different concrete classes. ... > public abstract class WidgetContext ...
    (microsoft.public.dotnet.general)
  • abstract and a static method (Help)
    ... I have a abstract class and some other than inherite from it ... I woul like to return a bitmap from the each subclass ... public class SegmantA: Segment ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Implementing IEnumerable in as abstract
    ... |I am developing an abstract class which implements IEnumerable. ... Assuming that you want to use explicit interface implementation to hide any ... protected abstract IEnumeratorGetEnumerator(); ... Joanna Carter ...
    (microsoft.public.dotnet.languages.csharp)

Loading