From course:
(Practice similar questions for free)
Advanced Concept C# Interview Questions
» Start this Course(Practice similar questions for free)
Question:
How do ref and out keywords work in C#, and how do they relate to Call By Reference?
Author: Lock HuynhAnswer:
In C#, the ref and out keywords are used to pass arguments by reference, allowing methods to modify the original variable. ref: Requires the variable to be initialized before passing to the method. It allows both reading and modifying the variable inside the method. out: Does not require the variable to be initialized before passing. The method must assign a value to the variable before it returns. Both ref and out enable Call By Reference, allowing methods to modify the caller's original data rather than a copy.
0 / 5 Â (0 ratings)
1 answer(s) in total