What are static member functions in C#?

CsharpProgrammingServer Side Programming

Static functions can access only static variables. The static functions exist even before the object is created.

Set static functions as −

public static int getNum() {}

The following is an example demonstrating the use of static functions −


 Live Demo

using System;

namespace Demo {
   class StaticVar {
      public static int num;

      public void count() {

      public static int getNum() {
         return num;

   class StaticTester {
      static void Main(string[] args) {
         StaticVar s = new StaticVar();


         Console.WriteLine("Variable num: {0}", StaticVar.getNum());


Variable num: 3
Published on 08-Aug-2018 07:37:52