473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to init my static variable like Java

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.
Oct 31 '06 #1
2 1203
The static constructor takes the form

static MyClass() {

}

Marc
Oct 31 '06 #2

"Marc Gravell" <ma**********@gmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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.
Oct 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Black Java | last post by:
Hi There, I'm new to Java. Having read a bunch of books, I wonder if static variable is initailized by defualt value? Textbooks only indicate that instance variable is implicitly initailized. ...
1
by: James | last post by:
Hello Java NG, I not sure if this is the right NG for this type of question but if not please let me know which is, TIA Any way first off let me say I'm a student and this WAS last weeks lab,...
2
by: Petra Neumann | last post by:
Hello, I just came across some sample code where a variable has been defined as: static public final int TABLE = 1, LIST = 2; I was wondering if there is a difference to writing public static...
3
by: paulw | last post by:
Hi I have a question: main() { static int i; printf("%d\n",i); // should I see see 0 or 5 ??? for (i=5;i<=15;i++) {...} // What's the meaning of static variable in
3
by: Dave | last post by:
Hi everyone, Is it possible, using an Attribute or by some other means, to notify the C# Compiler to serialize all static field's that have initializers before code in an explicit static...
44
by: John A. Bailo | last post by:
Dr. Dobbs has a /glowing/ article on Ruby on Rails this month. What do you guys think? Can it replace .net, php and java? And be the Open Source OOP web solution that is not bound to Sun or...
3
by: rwoo_98 | last post by:
Does anyone know the difference between defining a static variable inside Global vs using an Application variable? For example Using a static int variable. public class Global :...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
2
by: Christof Warlich | last post by:
Hi, I'm working on a (template) library that is up to now entirely implemented in header-files. This makes the library quite convenient to use as no extra object code needs to be linked when...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.