What is static keyword in c#?

Asked 24-Oct-2019
Updated 24-Oct-2019
Viewed 504 times

1 Answer


0

The static keyword in c # is used to declare static class or static data members or static property. A static class can only contain static data members, static methods and static constructor. We can access those static data members directly with a class name instead of creating on object of a class to access those properties.
Following is the example of defining a class with static properties and those can be access directly with a type instead of specific object name.
class User

{
public static string name, location;
public static int age;
}