Method Basics
In this page:
Method Basics
A method is a named, reusable block of code declared with a return type, a name, and a parameter list. Calling a method transfers control to its body and resumes the caller once it returns. Breaking logic into methods keeps programs organized and avoids repeating code.
Note: Method names conventionally use PascalCase in C#, like CalculateTotal.
Example: Method Basics
using System;
class Program
{
static void PrintBanner()
{
Console.WriteLine("=== Welcome ===");
}
static void Main(string[] args)
{
PrintBanner();
Console.WriteLine("Program running");
}
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: