Hi, I am porting an application written in java to .net (c#). The problem is that the java code contains many static initialisation blocks such as: class MyClass{ int x=0; static{ ... } ... } How can I do the same thing in c# (static initialisation blocks)?
Thank you, Dan
You just need to do: public class MyClass { int x=0; static MyClass() { // .. Put Static Construction Logic Here } }
In C#, they're called static constructors. See
Static Constructors for more information.
None
0 Points
1 Post
static blocks in c#
Aug 15, 2003 06:17 AM|dbunea|LINK
Member
13 Points
606 Posts
ASPInsiders
Re: static blocks in c#
Aug 15, 2003 09:42 AM|Ambrose|LINK
public class MyClass { int x=0; static MyClass() { // .. Put Static Construction Logic Here } }
In C#, they're called static constructors. See Static Constructors for more information.Silverlight MVP