Declare a member function as static. - CSharp Custom Type

CSharp examples for Custom Type:static

Description

Declare a member function as static.

Demo Code

using System;/*  w ww  . j  a v a 2s.  c om*/
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());
   }
}

Result


Related Tutorials