← Back to C# Course | Chapter 5: Methods | Lesson 2 of 6

Parameters

In this page:

  1. Parameters

Parameters

Parameters let a method receive input values from its caller, each with a declared type and name. Arguments are passed by value for value types by default, meaning the method gets its own copy. Multiple parameters are separated by commas in both the declaration and the call.

Note: Parameter names should describe their purpose, not just their type.

Example: Parameters

markup
using System;

class Program
{
    static void Greet(string name, int times)
    {
        for (int i = 0; i < times; i++)
        {
            Console.WriteLine($"Hello, {name}!");
        }
    }

    static void Main(string[] args)
    {
        Greet("Sam", 3);
    }
}
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.