static construction clause 
Author Message
 static construction clause

Hi,
I need to make a static initialization for a class as well
as in Java (called also static block), ie:

class Test {
  public Test() {...}
  static {
    System.out.println("Hello");
  }

Quote:
}

is it possible in C# ?

Thank you
Pierre



Fri, 30 Jan 2004 21:56:51 GMT  
 static construction clause
Quote:
> I need to make a static initialization for a class as well
> as in Java (called also static block), ie:

> class Test {
>   public Test() {...}
>   static {
>     System.out.println("Hello");
>   }
> }

> is it possible in C# ?

sure !
use the "class construtor" !
class Test {
  public Test() {/* */}
  static Test() {
    System.out.println("Hello");
  }
Quote:
}



Fri, 30 Jan 2004 22:36:06 GMT  
 static construction clause
Thanks a lot.

Pierre

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sat, 31 Jan 2004 00:23:49 GMT  
 static construction clause

Quote:
>-----Original Message-----
>Hi,
>I need to make a static initialization for a class as
well
>as in Java (called also static block), ie:

>class Test {
>  public Test() {...}
>  static {
>    System.out.println("Hello");
>  }
>}

>is it possible in C# ?

>Thank you
>Pierre
>.

Yes, you can write static constructors in C#.
The syntax is like following:
class Test {
  public Test() {...} //instance constructor
  static Test() {     //static constructor
    System.out.println("Hello");
  }

- Show quoted text -

Quote:
}



Sat, 31 Jan 2004 01:10:15 GMT  
 static construction clause
Thanks al lot

Pierre

Quote:

>Yes, you can write static constructors in C#.
>The syntax is like following:
>class Test {
>  public Test() {...} //instance constructor
>  static Test() {     //static constructor
>    System.out.println("Hello");
>  }
>}

>.



Sat, 31 Jan 2004 03:54:40 GMT  
 static construction clause
The idea seems very foolish since static refers to the class and a
constrcutro to a class's instance.


Sat, 31 Jan 2004 20:33:44 GMT  
 static construction clause
no, because a constructor never constructs, it only initializes, and that
is exactly what a static class constructor does -- initialization.
- Dominik
Quote:

> The idea seems very foolish since static refers to the class and a
> constrcutro to a class's instance.



Sun, 01 Feb 2004 23:57:24 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Construction of local static objects in a multithreaded environment

2. How can I control static object construction order?

3. Order of construction of static class members ?

4. Help Understanding Syntax Clauses

5. Large nested if clauses vs. many logical ANDs

6. I have a problem with the catch clauses!

7. Macro with if-else clause

8. Simulate the "PIC" clause in COBOL

9. CRecordset and WHERE clause

10. ODBC/CRecordset: changing sources, from clause

11. WHERE clause in a TRANSFORM

12. Help with creating SQL Select stmt with a WHERE clause on a Dat/Time field

 

 
Powered by phpBB® Forum Software