What is Ref and Out?
Ref and out are basically C# Keywords. These keywords are used for calling function by reference. These keywords passes the reference of the variable to the function instead of the value.
For example: Let's swap two integer variables values:
Ref and out are basically C# Keywords. These keywords are used for calling function by reference. These keywords passes the reference of the variable to the function instead of the value.
For example: Let's swap two integer variables values:
- public static void Swap(int a, int b)
- {
- int c = 0;
- c = a;
- a = b;
- b = c;
- Console.WriteLine("1) Values after swap a={0} b={1}",a,b);
- }
- static void Main(string[] args)
- {
- int a = 5;
- int b = 6;
- Swap(a,b);
- Console.WriteLine("2) Values after swap a={0} b={1}", a, b);
- Console.ReadKey();
- }
Here, we are swapping only the value but not swapping the value from actual address. If we want to swap value from memory location in C#, we need to use ref or out keyword.
For example
Dharmandar KumarPosted Oct 7, 2019, 11:34 AM
Https://dipoletechi.com/blogs/
Christopher AndrewsPosted Nov 18, 2015, 4:03 AM
Nice article. Also check this out- www.redfly.io
Dharmandar KumarPosted Oct 7, 2015, 6:46 AM
Thank you so much for reading my post....
Nilesh JadavPosted Oct 2, 2015, 4:59 AM
Nice one
Santhakumar MunuswamyPosted Oct 1, 2015, 4:11 PM
Welcome
Santhakumar MunuswamyPosted Oct 1, 2015, 4:11 PM
Good start