Click here to Skip to main content
15,922,650 members
Home / Discussions / C#
   

C#

 
GeneralRe: reguarding strings Pin
Anonymous10-Mar-03 11:05
Anonymous10-Mar-03 11:05 
GeneralAccessing vairable etc in a different class Pin
monrobot138-Mar-03 12:27
monrobot138-Mar-03 12:27 
GeneralRe: Accessing vairable etc in a different class Pin
leppie8-Mar-03 12:48
leppie8-Mar-03 12:48 
GeneralRe: Accessing vairable etc in a different class Pin
monrobot139-Mar-03 11:31
monrobot139-Mar-03 11:31 
GeneralRe: Accessing vairable etc in a different class Pin
jpwkeeper10-Mar-03 1:59
jpwkeeper10-Mar-03 1:59 
GeneralRe: Accessing vairable etc in a different class Pin
monrobot1310-Mar-03 15:42
monrobot1310-Mar-03 15:42 
GeneralRe: Accessing vairable etc in a different class Pin
jpwkeeper11-Mar-03 3:40
jpwkeeper11-Mar-03 3:40 
GeneralInherited Static Constructors Pin
moredip8-Mar-03 9:51
moredip8-Mar-03 9:51 
Hi all,

I'm having trouble with inheritted static constructors in C#, here's an example - a simple superclass that supplies a static OutputClassName() method to derived classes:
class Parent
    {
        static protected string className;
        static Parent()
        {
            className = "Parent";
        }
        static public void OutputClassName()
        {
            System.Console.Out.WriteLine( className );
        }
    }

    class ChildA : Parent
    {
        static ChildA()
        {
            className = "ChildA";
        }
    }

    class ChildB : Parent
    {
        static ChildB()
        {
            className = "ChildB";
        }
    }

Now when I run the following
Parent.OutputClassName();
ChildA.OutputClassName();
ChildB.OutputClassName();

I'd expect the following output:

Parent
ChildA
ChildB


but it's actually:

Parent
Parent
Parent


So it seems that inheritance polymorphism isn't available for the static members of a class. Is this intentional, and is there an elegant way around this?

TIA,

Pete
GeneralRe: Inherited Static Constructors Pin
Nnamdi Onyeyiri8-Mar-03 10:45
Nnamdi Onyeyiri8-Mar-03 10:45 
GeneralRe: Inherited Static Constructors Pin
moredip8-Mar-03 11:49
moredip8-Mar-03 11:49 
GeneralRe: Inherited Static Constructors Pin
leppie8-Mar-03 12:01
leppie8-Mar-03 12:01 
GeneralRe: Inherited Static Constructors Pin
moredip8-Mar-03 12:14
moredip8-Mar-03 12:14 
GeneralRe: Inherited Static Constructors Pin
leppie8-Mar-03 12:44
leppie8-Mar-03 12:44 
GeneralRe: Inherited Static Constructors Pin
moredip8-Mar-03 12:56
moredip8-Mar-03 12:56 
GeneralRe: Inherited Static Constructors Pin
leppie8-Mar-03 13:14
leppie8-Mar-03 13:14 
GeneralRe: Inherited Static Constructors Pin
moredip8-Mar-03 13:43
moredip8-Mar-03 13:43 
GeneralRe: Inherited Static Constructors Pin
moredip8-Mar-03 13:53
moredip8-Mar-03 13:53 
GeneralRe: Inherited Static Constructors Pin
moredip8-Mar-03 14:10
moredip8-Mar-03 14:10 
GeneralRe: Inherited Static Constructors Pin
leppie8-Mar-03 14:25
leppie8-Mar-03 14:25 
GeneralRe: Inherited Static Constructors Pin
moredip8-Mar-03 16:05
moredip8-Mar-03 16:05 
GeneralRe: Inherited Static Constructors Pin
leppie9-Mar-03 7:02
leppie9-Mar-03 7:02 
GeneralRe: Inherited Static Constructors Pin
moredip9-Mar-03 7:26
moredip9-Mar-03 7:26 
GeneralRe: Inherited Static Constructors Pin
leppie9-Mar-03 7:54
leppie9-Mar-03 7:54 
GeneralTextBox DataBinding Pin
leppie8-Mar-03 7:24
leppie8-Mar-03 7:24 
GeneralRe: TextBox DataBinding Pin
leppie8-Mar-03 7:31
leppie8-Mar-03 7:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.