Inheritence Accessing A Static Concrete Value

Is there a way to accomplish this using static members? I can get the correct behaviour using non static members and an abstract class but I dont want to instatiate the Foo class everytime I need to use the GetUpperName() method. Is this pattern just simply wrong? Is there a better/correct approach?


Code Snippet

publicclassFooBase

{

privatestaticstring name ="Should not see this.";

publicstaticstring Name

{

get {return name; }

set { name =value; }

}

publicstaticstring GetUpperName()

{

return name.ToUpper();

}

}

publicclassFoo :FooBase

{

static Foo()

{

Name ="How can I use this string in the FooBase class?";

}

}

[TestFixture]

publicclassFooTester

{

[Test]

publicvoid TestUpperToolName()

{

string expected ="HOW CAN I USE THIS STRING IN THE FOOBASE CLASS?";

string actual =Foo.GetUpperName();

Assert.AreEqual(expected,actual);

}

}

[3392 byte] By [mxmissile] at [2008-1-4]
# 1
There is not such thing as inheritance of static methods...If you look at the MSIL you will see that Foo.GetUpperName is c# syntactic sugar for FooBase.GetUpperName

IL_0007: call string ConsoleApplication1.FooBase::GetUpperName()

timvw at 2007-9-26 > top of Msdn Tech,Visual C#,Visual C# General...