
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What are static member functions in C#?
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 −
Example
using System; namespace Demo { 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(); } } }
Output
Variable num: 3
- Related Articles
- How static variables in member functions work in C++?
- What are member functions of a class in C#?
- Static Data Member Initialization in C++
- Const member functions in C++
- Static functions in C
- C++ static member variables and their initialization
- Count the number of objects using Static member function in C++
- Count the number of objects using Static member function in C++ Program
- What are functions in JavaScript?
- What are the member variables of a class in C#?
- What are static imports in java? Example.
- What are late static bindings in PHP?
- What are callback functions in JavaScript?
- What are variadic functions in Java?
- What are generator functions in JavaScript?

Advertisements