Parameters

Another way to define variables is through the use of formal method parameters. Table D.1 outlines the four types of method parameters.

Table D.1. Parameter Types in C#
Parameter Type Modifier Description
value none Modifications do not impact original argument passed into the method.
reference ref Modifications directly impact original argument passed into the method.
output out Used for passing values out of a method. Initial value is inconsequential.
parameter array params Enables variable length parameter lists.

Consider the following class, which employs each of the parameter types:

 using System; class Test { public void ValueParamMethod(int a) { a += 2; // the original parameter is not modified } public void RefParamMethod(ref ...

Get ASP.NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.