Parameters and overloads
Parameters describe a method’s inputs. Overloads are methods with the same name but different permitted parameter signatures. The compiler selects an applicable overload using the supplied arguments and conversions; the choice is not based on what a method prints.
using System;Console.WriteLine(Delivery.Cost(3));Console.WriteLine(Delivery.Cost(3, 2));static class Delivery{ public static int Cost(int boxes) => Cost(boxes, 1); public static int Cost(int boxes, int rate) => boxes * rate;}One argument selects the first overload, which delegates to the two-argument method. These rates are fictional integers.
Expected output (reasoned, not executed):
36Overloads and signatures
For ordinary non-generic methods, the name and parameter types, order and passing modes matter to the signature. Return type, parameter names, optional defaults and params alone cannot distinguish overloads. A value parameter can distinguish an overload from a by-reference parameter, but two members cannot differ solely by ref, out, in or ref readonly. The examples below use ordinary value parameters. Local functions cannot be overloaded within the same local declaration space, so the first example uses methods inside a class.
Named, optional and variable-length inputs
A named argument uses name: value, making meaning explicit. Optional parameters have defaults that callers can omit; changing a library default may require recompiling callers to observe it. A params int[] parameter, placed last, accepts separate integers or an existing array. C# 13 and later support additional eligible parameter collection types, but this lesson uses arrays only. Use consistent parameter names across overloads and avoid overlapping optional signatures that make calls ambiguous.
using System;Console.WriteLine(Label("A"));Console.WriteLine(Label(copies: 2, name: "B"));static string Label(string name, int copies = 1) => $"{name}: {copies}";The first call uses the default. The second matches arguments by name, despite their reversed order. Expressions are evaluated in call-site order.
Expected output (reasoned, not executed):
A: 1B: 2using System;Console.WriteLine(Total(2, 4, 1));Console.WriteLine(Total());int[] batch = { 5, 6 };Console.WriteLine(Total(batch));static int Total(params int[] quantities){ int sum = 0; foreach (int quantity in quantities) sum += quantity; return sum;}The expanded calls supply elements of an array, including an empty array for zero arguments. The last call passes an existing array.
Expected output (reasoned, not executed):
7011Common mistake and correction
Do not declare two methods that differ only by return type, such as int Size(int n) and long Size(int n). The signatures collide. Choose a different name or a meaningful parameter difference. If a call is ambiguous, design a clearer API instead of relying on accidental conversions.
Try it yourself
Create a class with Fee(int items) delegating to Fee(int items, int rate) with a default rate of 2. Test Fee(3), Fee(3, 5), Fee(rate: 4, items: 0). Restrict inputs to 0 through 100.
Next: Value parameters and ref/out/in. Examples target C# 14 / net10.0. They are static study material; compiler and ByteMind execution have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Parameters and overloads — knowledge check
Apply the lesson concepts to the following scenarios.
Which pair can overload within a class?
What value does Label("A") use for copies when copies defaults to 1?
What does Total() receive with params int[] quantities?
What determines the selected ordinary overload?
What does Fee(rate: 5, items: 2) mean?