•Passing a value-type
data to a method by value means passing a copy of the variable to the method.
•Any changes to the
parameter that take place inside the method have no affect on the original data in the calling method.
struct Square
{
void SquareMe(int x)
{
int s;
s = x * x;
Console.WriteLine("Square of {0} is {1}", x, s);
}
void increment(int n)
{
n = n + 1;
Console.WriteLine("\n****in method my value is {0}", n);
}
static void Main()
{
int n;
Console.WriteLine("Enter Any Number");
n = int.Parse(Console.ReadLine());
Console.WriteLine("\nBefore Calling method...My Value is {0}", n);
Square o = new Square();
o.increment(n);
Console.WriteLine("\nAfter Calling method....My Value is {0}", n);
Console.WriteLine("Press any key to Exit");
Console.ReadKey();
}
}
No comments:
Post a Comment