
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Reference (ref) Parameter of an Array Type in C#
Declare the reference parameters using the ref keyword. A reference parameter is a reference to a memory location of a variable. When you pass parameters by reference, unlike value parameters, a new storage location is not created for these parameters.
Declare a ref parameter −
public void swap(ref int x, ref int y) {}
Declare a ref parameter of array type −
static void Display(ref int[] myArr)
The following is an example showing how to work with ref parameter of an array type in C# −
class TestRef { static void Display(ref int[] myArr) { if (myArr == null) { myArr = new int[10]; } myArr[0] = 345; myArr[1] = 755; myArr[2] = 231; } static void Main() { int[] arr = { 98, 12, 65, 45, 90, 34, 77 }; Display(ref arr); for (int i = 0; i < arr.Length; i++) { System.Console.Write(arr[i] + " "); } System.Console.ReadKey(); } }
Advertisements