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

Output:

John

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

Output:

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






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA