Returning null or what? I have a C# function like below, and in the else block, the function must return something. I don't know whether returning null is a good practice or not.

public Nullable&lt;Point&gt; GetSprite(int x, int y)
{
    if (x &lt;= xCount &amp;&amp; y &lt;= yCount)
    {
        return new Point(x * spriteHeight, y * spriteWidth);
    }
    else
    {
        return null;
    }
}
Yes, you could just write:

public Point GetSprite(int x, int y)
{
    if (x &lt;= xCount &amp;&amp; y &lt;= xCount)
    {
        return new Point(x * spriteHeight, y * spriteWidth);
    }

    return null;
}


And write in the documentation it could return null if if (x &lt;= xCount &amp;&amp; y &lt;= xCount)

So who use your code could just write

Point point = GetSprite(x, y);
if (point == null) { /* something went wrong, check variables! */ }
else { /* ok! go ahead! */ }


I found this syntax very useful, and could not lead to bugs if the programmer is alerted about the null.

And, anyway you don't need the else block since the return call will stop the function (except if there are any finally blocks, but it's not the case.).