Static methods

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#.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.175.253