K
knocte
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
--
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
--