Back to course

Methods: Basics and Declaration

.NET Zero to Hero: Master C# and Modern App Development

What are Methods?

A method (or function) is a block of code which only runs when it is called. You can pass data, known as parameters, into a method.

Syntax:

csharp static void MyMethod() { Console.WriteLine("Executing method..."); }

Calling a Method:

Inside Main: csharp MyMethod();

  • void means the method doesn't return a value.
  • static means it belongs to the class, not a specific object.