IT. Expert System.

C#

ref


The ref keyword causes an argument to be passed by reference, not by value. The effect of passing by reference is that any change to the parameter in the called method is reflected in the calling method. For example, if the caller passes a local variable expression or an array element access expression, and the called method replaces the object to which the ref parameter refers, then the caller’s local variable or the array element now refer to the new object. Note== Do not confuse the concept of passing by reference with the concept of reference types. The two concepts are not the same. A method parameter can be modified by ref regardless of whether it is a value type or a reference type. There is no boxing of a value type when it is passed by reference.

Syntax:
functionName(ref value1); // Pass as reference parameter


Example:

using System;

class Program
{
    static void Main()
    {
	string value1 = "cat"; // Assign string value
	SetString1(ref value1); // Pass as reference parameter
	Console.WriteLine(value1); // Write result

	string value2; // Unassigned string
	SetString2(1, out value2); // Pass as out parameter
	Console.WriteLine(value2); // Write result
    }

    static void SetString1(ref string value)
    {
	if (value == "cat") // Test parameter value
	{
	    Console.WriteLine("Is cat");
	}
	value = "dog"; // Assign parameter to new value
    }

    static void SetString2(int number, out string value)
    {
	if (number == 1) // Check int parameter
	{
	    value = "one"; // Assign out parameter
	}
	else
	{
	    value = "carrot"; // Assign out parameter
	}
    }
}

/*Output

Is cat
dog
one*/


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 1234 / . Delta: 0.00574 с