ex-04-12

来自「Programming Csharp Source Code(代码) Prog」· 代码 · 共 38 行

TXT
38
字号
//Example 04-12: Using static public constants

public class RightNow
{
   static RightNow()
   {
      System.DateTime dt = System.DateTime.Now;
      Year =      dt.Year;
      Month =     dt.Month;
      Date =      dt.Day;
      Hour =      dt.Hour;
      Minute =    dt.Minute;
      Second =    dt.Second;
   }


   // private member variables
   public static int Year;
   public static int Month;
   public static int Date;
   public static int Hour;
   public static int Minute;
   public static int Second;  
}

public class Tester
{
   static void Main()
   {
      System.Console.WriteLine ("This year: {0}", 
             RightNow.Year.ToString());
      RightNow.Year = 2002;
      System.Console.WriteLine ("This year: {0}", 
      RightNow.Year.ToString());
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?