C# return variables

Posted by pb01 on Programmers See other posts from Programmers or by pb01
Published on 2012-03-27T12:30:33Z Indexed on 2012/03/27 17:42 UTC
Read the original article Hit count: 354

Filed under:
|
|

In a debate regarding return variables, some members of the team prefer a method to return the result directly to the caller, whereas others prefer to declare a return variable that is then returned to the caller (see code examples below)

The argument for the latter is that it allows a developer that is debugging the code to find the return value of the method before it returns to the caller thereby making the code easier to understand: This is especially true where method calls are daisy-chained.

Are there any guidelines as to which is the most efficient and/or are there any other reasons why we should adopt one style over another?

Thanks

    private bool Is2(int a)
    {
        return a == 2;
    }

    private bool Is3(int a)
    {
        var result = a == 3;
        return result;
    }

© Programmers or respective owner

Related posts about c#

Related posts about coding-style