
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- How static variables in member functions work in C++?
- What are member functions of a class in C#?
- Const member functions in C++
- Static Data Member Initialization in C++
- Static functions in C
- C++ static member variables and their initialization
- What are virtual functions in C#?
- What are the member variables of a class in C#?
- Count the number of objects using Static member function in C++
- What are the C library functions?
- Count the number of objects using Static member function in C++ Program
- What are Local functions in C# 7.0?
- What are the predefined functions in C language?
- What are string searching functions in C language?
- What are static members of a C# Class?
Advertisements