Explain the significance of static method
Static methods are used when we want only one copy of that method to perform action and remain active at a single point in time.
Imagine a scenario where you need a class to connect to the database once and remain as it is for the entire application.
public static class MyDbConnection
{
public static void ConnectToDb()
{
//code to connect to database
}
}
public void SomeMethod()
{
MyDbConnection.ConnectToDb();
}
You don’t want different instances of this class to be created and connect to the database again and again, hence make a static method in a static class.