Pass A Reference To A Function, Method, etc

Passing by reference enables function members, methods, properties, indexers, operators, and constructors to change the value of the parameters and have that change persist in the calling environment.

You just use the 'ref' or 'out' keyword:

'ref' tells the compiler that the object is initialized before entering the function

'out' tells the compiler that the object will be initialized inside the function

So 'ref' is two-ways and 'out' is out-only

	public void MyMethodName(ref int[] BookIds, ref string[] BookLanguages)
	public void MyMethodName(out int[] BookIds, out string[] BookLanguages)

Calling the method

You need to use the 'ref' or 'out' keyword here too

	MyMethodName(ref TheBookIds, ref TheBookLanguages);



We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.