What is the difference between ref and out keywords in method parameters?
What is the difference between ref and out keywords in method parameters?
Student
The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
In C#, both
refandoutare used to pass arguments by reference to a method, but they differ in terms of initialization requirements and intended purpose.Key Differences
refoutrefExamplexbefore passingxinside the methodoutExamplexandydon’t need initialization before the callCompile-Time Rules
refoutWhen to Use What?
refoutrefBonus:
ref readonlyYou can also use
ref readonlyto pass by reference without allowing modification.