Code:
using System;
class passingargs
{
static void SqIt(int m)
{
m *= m;
Console.WriteLine("The value that is stored in the method: {0}", m);
}
public static void Main()
{
int passInt = 5;
Console.WriteLine("The result before invoking the method: {0}",
passInt);
SquareIt(passInt);
Console.WriteLine("The result after invoking the method: {0}",
passInt);
}
}
As in the code you can see in the code the difference when the arguments is passed as a value or reference , you will clearly get the difference when you execute this code , any change made in the actual parameter he value remains intact , but when the argument is passed as reference any change made in the actual parameters reflects in the result as well.
Bookmarks