Both
refandoutare used to pass arguments by reference in C#.That means the method can modify the original variable value.
1.
refKeyword
Variable must be initialized before passing
Used when method reads and modifies the value
Memory must already contain a value
Example
void AddTen(ref int number){number = number + 10;}int x = 5;AddTen(ref x);// x becomes 15
2.
outKeyword
Variable does NOT need initialization before passing
Method must assign a value before returning
Used mainly for returning multiple values
Example
void GetNumber(out int number){number = 20;}int x;GetNumber(out x);// x becomes 20
Key Differences (List Format)
Initialization
ref→ Must initialize before passing
out→ No need to initialize before passingValue Assignment Inside Method
ref→ Optional to assign
out→ Mandatory to assignUsage Purpose
ref→ Modify existing value
out→ Return value from methodMemory
Both pass variable reference (same memory location)
Simple Rule to Remember
If variable already has value → use
refIf method will create and return value → use
out
Every Question..What does it mean? Why is this? How it works?
Microsoft .Net (pronounced dot (.) net) may be a package element that runs on the Windows software package.
.Net provides tools and libraries that change developers to form Windows package a lot of quicker and easier.
Microsoft describes it as:".Net is that the Microsoft internet Service strategy to attach data, people,
system and devices through software".I'm Choulla Naresh..!