// 1) Passing By Value
// C# creates a copy of the given variable's value and put it
// into the method's parameter. Ergo you can do any changes you
// want on the parameter within the method without making any
// changes on the argument. I.e you are changing only the "Copy
// of the Argument's Value". Not given argument or argument's value.
// -By default, C# will use -By Value- technic to passing the arguments.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewSandbox
{
class Program
{
static void YourMethod(int m){
m = m*m;
}
static void Main(string[] args)
{
int number = 5;
YourMethod(number); //output will be 5
}
}
}
// Brief explanation: The method will operate on the VALUE, not the ACTUAL VARIABLE.
Hiç yorum yok:
Yorum Gönder