C# Ref and Out Keywords
Ref - Ref is two ways from caller to callee and back.
static void Main(string[] args)
{
int outSideVar = 10;
GetNextNameByOut(out outSideVar);
Console.WriteLine(outSideVar);
}
static void GetNextNameByOut(out int inSideVar)
{
inSideVar = inSideVar + 20;
}
Out - Data sent from the caller has been discarded and its mandatory to initialize the variables inside the callee.
Out is a ne way from callee to caller.
static void Main(string[] args)
{
int outSideVar = 10;
GetNextNameByOut(out outSideVar);
Console.WriteLine(outSideVar);
}
static void GetNextNameByOut(out int inSideVar)
{
inSideVar = 100;
inSideVar = inSideVar + 20;
}
Video reference - https://www.youtube.com/embed/lYdcY5zulXA
Content reference: https://www.codeproject.com/Articles/1026771/Csharp-Out-VS-Ref
Comments
Post a Comment