What is static keyword in c#?

0 votes
41 views
Pradeep kumar Patel asked 24-Oct-2019 in Programming Language by Pradeep kumar Patel
edited 24-Oct-2019 by Pradeep kumar-Patel

What is static keyword in c#?

1 Answer

0 votes
Pradeep kumar Patel answered 24-Oct-2019 by Pradeep kumar Patel
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;
}