
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is a 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(); } }
- Related Articles
- What is difference between a pointer and reference parameter in C++?
- What is an Optional parameter in C#?
- What is the difference between a weak reference and an unowned reference?
- What are Ref locals and Ref returns in C# 7.0?
- Value Type vs Reference Type in C#
- Is it possible to instantiate Type-parameter in Java?
- Is an array a primitive type or an object in Java?
- How to pass an array as a URL parameter in Laravel?
- What is the usage of ref, out, and in keywords in C#?
- What is a final parameter in java?
- How to create a constructor reference for an array in Java?
- What is a reference point?
- How to pass an array by reference in C++
- What is a reference variable in C++?
- What is final parameter in Java

Advertisements