Method Parameters

In C#, method parameters default to “by value.” C# does, however, provide for other types of method parameters. You can specify method parameters by using the keywords out, ref, or params.

out

Values passed as out parameters reflect any changes made to them while inside the method they were passed. This capability can be useful when multiple values need to be returned from a method. Listing A.29 shows the use of out parameters.

Listing A.29. Using an out Parameter
 1: using System; 2: 3: class Rectangle{ 4: 5: private int Length = 0; 6: private int Width = 0; 7: private int Height = 0; 8: 9: public Rectangle(int length, int width, int height){ 10: Length = length; 11: Width = width; 12: Height = height; 13: } 14: 15: public ...

Get Building e-Commerce Sites with the .NET Framework 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.