C# Tutorial | Passy By Value and Reference

This video will give you a complete training in Passy By Value and Reference in C#

For Complete C# Online Training Course Please Visit https://www.bestdotnettraining.com/csharp-online-training

Passing parameters by value, out or reference

using System;

class Program


public static void Main()


int n1, n2, n3;

n1 = n3 = 10;

Foo(n1, out n2, ref n3);

Console.WriteLine(n1 + ” ” + n2 + ” ” + n3);


static void Foo(int a, out int b, ref int c)



b = 20;




The argument “n2” is passed by reference to “b”, i.e. both “b” and “n2” reference to same memory and hence change made to “b” is also reflected in “n2”.

Out parameter must be initialized in the method and are generally used in situations where we want to return more than one value from the method.

Return Type Rule
If a method has return type anything other than “void”, all code paths in it must return a value.
The example below compilation error because if a==0 nothing is mentioned as return value:
static int Foo(int a)


if (a != 0)

return a;

This video was compiled by Mr. Sandeep Soni, a Microsoft Certified Trainer and an Azure Solution Architect. Know more – https://www.bestdotnettraining.com/sandeepsoni

Please subscribe to our channel for more related videos: https://www.youtube.com/user/Deccansoft123

For any course-related queries, reach us @ +91 8555823343 / +91 8008327000 Kashmira Shah

Please leave your comment about the videos.

For more updates on courses and tips follow us on:
– Facebook: https://www.facebook.com/DeccansoftHome
– Twitter: https://twitter.com/deccansoft
– LinkedIn: https://in.linkedin.com/company/deccansoft-software-services
– Website: https://www.deccansoft.com/ or https://www.bestdotnettraining.com/
– Join our WhatsApp group – https://chat.whatsapp.com/HzE43FXv0HJ2z5qGSPDren


Add Yours →

Leave a Reply