Static Function

Static functions

If we declare function as static we can call the function by the class name.function name rather creating an instance of the class and then calling the function.

public
class Class1
{
    public void function1() 
    {
        Class2.function2();
    }
}
public
class Class2
{
    public static void function2()
    {
        MessageBox.Show("Anu");
    }
}

or else if we are not using static function

public
class Class1
{
    public void function1()
    {
        Class2 cls= new Class2();
        cls.function2();
    }
}
public
class Class2
{
    public void function2() 
    {
        MessageBox.Show("Anu"); 
    }
} 

It will not work if we call function2() as class2.function2() when declared as static ie public static void function2()