25-10-2012, 02:35 PM
CLASSES AND OBJECTS USING OUT, REF AND PARAMS
CLASSES AND OBJECTS USING OUT, REF AND PARAMS.doc (Size: 487 KB / Downloads: 28)
Hardware / Software Required
Software requirements
Microsoft Visual Studio 2008
Hardware requirements
Pentium IV
RAM 512 MB
Detailed Description of Exercise
By default, value types are passed into methods by value. This means that when a value object is passed to a method, a temporary copy of the object is created within that method. Once the method completes, the copy is discarded. Although passing by value is the normal case, there are times when you will want to pass value objects by reference. C# provides the ref parameter modifier for passing value objects into a method by reference, and the out modifier for those cases in which you want to pass in a ref variable without first initializing it. C# also supports the params modifier, which allows a method to accept a variable number of parameters.
Use of ref Keyword:
Ref parameters are changed at the calling site. They are passed as references, not values. This means you can assign the parameter in the called method and have it also be assigned at the calling site. Ref arguments are powerful and useful.