- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 is a static class in C#?
The C# static class cannot be instantiated and can only have only static members. The static class in C# is sealed and cannot contain instance constructors.
The following is an example with static class and static members −
Example
using System; public static class Demo { public static float PI = 3.14f; public static int calc(int n){return n*n;} } class Program { public static void Main(string[] args) { Console.WriteLine("PI: "+Demo.PI); Console.WriteLine("Square: " + Demo.calc(3)); } }
Above, the static class is −
public static class Demo { public static float PI = 3.14f; public static int calc(int n){return n*n;} }
Above we have the following static members −
public static float PI = 3.14f; public static int calc(int n){return n*n;}
Advertisements