Here, you can see we have create one method named “Square”. When we call method Square() in Main() method and pass a variable a then a copy of the variable a is passed to the Square method and not the variable a. Also, note that i is the local variable in Square() and a is the local variable in Main(). Hence, variables can be accessed within their containing methods only.

C# ref Keyword

C# provides a keyword, ref, which means argument to be passed by reference, not by value. So the effect of passing by reference is that any change to the parameter in the method is reflected in the underlying argument variable in the calling method.

To use a ref parameter, Both the method signature and calling method should be declared as ref keyword.