'Not all codepaths return a value' -- Good Catch Error of C# Compiler
'Not all codepaths return a value' -- Good Catch Error of C# Compiler
In most programming languages particularly when writing functions that involve complex conditions to evaluate and iterations to process, it is really a nightmare when we need to exit from the function from more than one place. Unless the function has a return type of void, it is going to be a pain for the caller of the function since if the exit in the callee is not accompanied by a proper return value, there is going to be an undefined (aka) NULL for the caller which it needs to handle.
I just wanted to share that in C#, the compiler catches this potential issue and flags it as an error 'Not all codepaths return a value'. Now you know and you can be sure to visit and review all exits from the function and ensure that the return is accompanied by a proper value to the return variable.
In most programming languages particularly when writing functions that involve complex conditions to evaluate and iterations to process, it is really a nightmare when we need to exit from the function from more than one place. Unless the function has a return type of void, it is going to be a pain for the caller of the function since if the exit in the callee is not accompanied by a proper return value, there is going to be an undefined (aka) NULL for the caller which it needs to handle.
I just wanted to share that in C#, the compiler catches this potential issue and flags it as an error 'Not all codepaths return a value'. Now you know and you can be sure to visit and review all exits from the function and ensure that the return is accompanied by a proper value to the return variable.
![[Lavanya Deepak]](http://img.photobucket.com/albums/v31/vdeepakkumar/lvdp.gif)

![[Microsoft Certified Professional]](http://img12.photobucket.com/albums/v31/vdeepakkumar/mcp.gif)



0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home