how to init my static variable like Java

W

Wu JianHua

Hi£¬ I am new to C#, in Java I can code as following.

class MyClass
{
public static MyClass C1 = null;
public static MyClass C2 = null;

private MyClass
{
}

static
{
// init C1 and C2 here.
}

......
}

How to code in C#, please help me.
Thanks.

wu jianhua.
 
B

Ben Voigt

Marc Gravell said:
The static constructor takes the form

static MyClass() {

}

Marc

And you should either initialize the variable inline, or in the static
constructor, but not both.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top