Use a static constructor : Static : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » Static »

 

Use a static constructor









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/


// Use a static constructor. 
 
using System; 
 
class Cons { 
  public static int alpha; 
  public int beta; 
 
  // static constructor 
  static Cons() { 
    alpha = 99; 
    Console.WriteLine("Inside static constructor."); 
  } 
 
  // instance constructor 
  public Cons() { 
    beta = 100; 
    Console.WriteLine("Inside instance constructor."); 
  } 
} 
  
public class ConsDemo { 
  public static void Main() {   
    Cons ob = new Cons(); 
 
    Console.WriteLine("Cons.alpha: " + Cons.alpha); 
    Console.WriteLine("ob.beta: " + ob.beta); 
                  
  } 
}
           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» Static