In C#, a class can have two types of methods: static methods and non-static methods. Static methods are shared across the different instances of the class objects, whereas non-static methods are unique for each instance. Just like static member variables, we can declare a method as static by the use of the static keyword and can access them by directly using the class name.
The following code example indicates how we create a static method in a class:
internal class Configuration
{
public static string ConnectionString;
public static void CreateConnectionString()
{
}
}
To execute a static method, we can use the following code snippet:
Configuration.CreateConnectionPath();
In the next section, we will look at constructors and how they are implemented in C#.