Fix To: The Out Parameter Must Be Assigned to Before Control Leaves the Current Method

Introduction

  • The out keyword causes arguments to be passed by reference.
  • To use an out parameter, both the method definition and the calling method must explicitly use the out keyword.
  • Although variables passed as out arguments do not have to be initialized before being passed, the called method is required to assign a value before the method returns.

Example

Simple Program to check whether the given character exists or not,


  1.  

Output

Output

When the Problem Occurs.

code

Note

In the above program, even though you assigned the out variable value inside the looping/case statement, if you don’t assign any value in the method definition like the above snagit then you will get the following error:

error

Conclusion

I hope the above information is useful for beginners, kindly let me know your thoughts.

122 total views, 5 views today

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *