Static in C# | What is static | Static Methods & Classes | C# Bangla Tutorial | Advanced C#

 

What is Static?

C# includes static keyword just like other programming languages such as C++, Java, etc. The static keyword can be applied on classes, variables, methods, properties, operators, events and constructors.

Static Class

A static class is declared with the help of static keyword. A static class can only contain static data members, static methods, and a static constructor. It is not allowed to create objects of the static class. Static classes are sealed, means one cannot inherit a static class from another class.

Important points


1. Static variables and methods are associated with the class, not any specific instance of the class.
2. Variables declared static are commonly shared across all instances of a class.

Limitation of using static keyword


1. Static keyword cannot be used by indexers, destructors, or types other than classes.
2. A static member is not referenced through an instance.
3. It is not allowed to use this to reference static methods or property accessors.
4. If static keyword is used with the class, then the static class always contain static members.


إرسال تعليق

أحدث أقدم