Javatpoint Logo
Javatpoint Logo

C# Ref returns and locals

C# ref keyword allows a method to return reference rather than a value. In C# prior versions, a method can return only value.

A variable that holds returned reference known as ref local.

A method that returns reference has certain restrictions that are listed below.

  • Method can't use void return type
  • Method can't return local variable
  • Method can't return null value
  • Method can't return constant, an enumeration, and property of a class or struct

Let's see an example.

C# Ref Returns Example



Ref local is a variable that is used to store the reference returned by the method. Let's see an example.

C# Ref Local Example


Array: [Rahul,John,Mayank,Irfan]
Updated array: [Rahul,John,Mayank,Peter]

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA