C# MethodsLesson 22Free preview
C# Method Parameters
This lesson is part of C# · All levels
Summary
A parameter is a variable that a method accepts, whereas an argument is the actual value that is sent at the time of calling. C# supports default value parameters, writing arguments by name, and params to send multiple values at once. There's also ref and out to interact with variables outside the method.
Key points
- Parameters are defined in parentheses method, the argument is filled when the method is called.
- Optional parameters are given a default value so it is not mandatory for callers to fill in.
- Named arguments allow for omitting or selectively sorting arguments using parameters.
- Params receive the number of dynamic arguments of the same type.
- Ref sends the variable back and forth, whereas out is used to fill out the value of the method.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.