C#静态函数

using System;namespace StaticVarApplication {class StaticVar {public static int num;public void count() {

编程学习网为您整理以下代码实例,主要实现:C#静态函数,希望可以帮到各位朋友。

using System;

namespace StaticVarapplication {

   class StaticVar {
      public static int num;

      public voID count() {
         num++;
      }

      public static int getNum() {
         return num;
      }
   }

   class StaticTester {

      static voID Main(string[] args) {
         StaticVar s = new StaticVar();
         s.count();
         s.count();
         s.count();
         Console.Writeline("Variable num: {0}", StaticVar.getNum());
         Console.ReadKey();
      }
   }
}

本文标题为:C#静态函数