CHASH Tutorial



C# STATIC METHODS


C# Static Methods

A static method belongs to the class itself rather than an instance of the class. You can call a static method without creating an object of the class.

Key Points

  • Can be called using the class name directly.
  • Cannot access instance (non-static) members directly.
  • Useful for utility or helper functions.

Example: Using Static Method

class MathHelper
{
    public static int Square(int number)
    {
        return number * number;
    }
}

class Program
{
    static void Main()
    {
        // Calling static method without creating an object
        int result = MathHelper.Square(5);
        Console.WriteLine(result);  // Output: 25
    }
}
  

Usage Tips

  • Use static methods for operations that don’t depend on object state.
  • Good for mathematical operations, helper functions, or factory methods.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review