In how many ways you can pass parameters to a method?
In how many ways you can pass parameters to a method?
There are several ways to pass parameters to a method in C#:
By Value: This is the default method of passing parameters in C#. When you pass a parameter by value, a copy of the parameter's value is passed to the method. Any changes made to the parameter inside the method do not affect the original value outside the method.
By Reference: To pass a parameter by reference, you need to use the ref
keyword. When you pass a parameter by reference, you pass a reference to the original variable, not a copy of its value. Any changes made to the parameter inside the method will affect the original variable outside the method.
Using Output Parameters: Output parameters are used to return multiple values from a method. To use output parameters, you need to use the out
keyword. Output parameters are similar to reference parameters, but they do not require the variable to be initialized before passing it to the method.
Using Optional Parameters: Optional parameters allow you to specify default value...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào