0

I have a base class with a protected-level static variable, a protected-level static function, and a public function:

public class BaseClass
{
    protected static int Size = 4;

    public static byte[] DoSomething(byte[] params)
    {
        // use Size somehow
        params = DoSomethingElse(params);
        return params;
    }

    protected static byte[] DoSomethingElse(byte[] params)
    {
        // do whatever
        return params;
    }
}

And a derived class that hides/overrides the protected-level variable and function:

public class DerivedClass : BaseClass
{
    public new static int Size = 2;

    protected new static byte[] DoSomethingElse(byte[] params)
    {
        // do something different than base class
        return params;
    }
}

Now, when I call DerivedClass.DoSomething, I want the Size value and DoSomethingElse from the DerivedClass to be used, but the BaseClass values are used instead. Is there a way to make this use the DerivedClass variable and method?

1 Answers1

0

You can't override static members. They belong to the class itself and are not associated with any instance of a class, so the concept is not applicable.

eol
  • 23,236
  • 5
  • 46
  • 64