Static constructor 2 : static constructor « Class « C# / CSharp Tutorial






using System;

class MyClass
{
   private static Random RandomKey;

   static MyClass()                     
   {
      RandomKey = new Random();                   
   }

   public int GetValue()
   {
      return RandomKey.Next();
   }
}

class Program
{
   static void Main()
   {
      MyClass a = new MyClass();
      MyClass b = new MyClass();
      Console.WriteLine("Next Random #: {0}", a.GetValue());
      Console.WriteLine("Next Random #: {0}", b.GetValue());
   }
}
Next Random #: 1768997546
Next Random #: 1565321362








7.43.static constructor
7.43.1.Static Constructors
7.43.2.Static constructor 2