A static keyword means something else in C, but in C # and Java it declares methods and variables as a class, not an object.
You would like to use it for methods and variables that do not need data from a specific object, but use the same data for each object of this type.
For example, String.Format () is a static method of the String class. You call this in your code without creating an instance of String. Similarly, Math.Pi will be a class variable.
But something like a length method makes no sense if it does not act on a particular instance of the string, so it should be an instance method. For example, x = "hello" .Length ();
So, if you want your method to be called only with the class name and not with the object, you make a static method. Note that such a method can only refer to static variables and call static methods, since it does not have an object with which you can refer to non-static elements.
In C, the static keyword denotes a file scope. A static variable or top-level function does not get its name exported to another compiled object code. Thus, two files can declare static variables with the same name, and not create a conflict. We do not have this problem in C #, because there are namespaces, as well as private, protected and public keywords, to indicate visibility.
Another value for static variables inside a function in C. These variables retain their value between function calls. For example, you can use it to count the number of times a function has been called. Static variables in C # also have this property, but you do not declare them inside a method, as in C, only inside a class.