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.
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
}
}
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!