/*
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);
}
}
|