Override static derived variable
- From: knocte <knocte@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 19 Jun 2005 16:22:24 +0200
Hello.
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.
Testcase:
using System;
namespace Test
{ abstract public class X {
protected static string var = "x"; public static void print_my_var(){
Console.WriteLine("my var is " + var);
}
} public class A : X {
protected static new string var = "a";
} public class B : X
{
protected static new string var = "b";
} class ClassTest { [STAThread]
static void Main(string[] args)
{
X.print_my_var();
A.print_my_var();
B.print_my_var();
}
}
}
result: my var is x my var is x my var is x
expected results: my var is x my var is a my var is b
How can obtain the expected results using static methods and static variables and without creating the static method A or B?
Thanks in advance.
Andrew
-- .
- Follow-Ups:
- Re: Override static derived variable
- From: Chad Z. Hower aka Kudzu
- Re: Override static derived variable
- From: Joanna Carter \(TeamB\)
- Re: Override static derived variable
- Prev by Date: Re: DateTime Null value in Typed DataSet gives Invalid Cast Exception - Please help !!!
- Next by Date: attribute??
- Previous by thread: How to transfer a string to char array
- Next by thread: Re: Override static derived variable
- Index(es):
Relevant Pages
|