?? Operator (C# Reference)

This operator allows you to supply an alternative value if the value being supplied is null. It only works on nullable datatypes but with a bit of googling came accross this article.

public int CurrentPage
{
    get
    {
        return (int)(ViewState["_CurrentPage"] ?? 0);
    }
    set
    {
        this.ViewState["_CurrentPage"] = value;
    }
}

The offical Microsoft article

Output Parameters with returned value

When using output parameter values you need to check that the value is not DBNull before using it…

using (SqlConnection conn = new SqlConnection())
{
    conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings.Get("DBConnection").ToString();
    conn.Open();
    using (SqlCommand cmd = new SqlCommand())
    {
        cmd.Connection = conn;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new SqlParameter("@ChapterId", _ChapterId));
        cmd.Parameters.Add(new SqlParameter("@Sequence", _Sequence));
        cmd.CommandText = "Get_ContentPrevNext";
        SqlParameter parameterPreviousId = new SqlParameter("@PreviousId", System.Data.SqlDbType.Int)
        {
            Direction = System.Data.ParameterDirection.Output
        };
        cmd.Parameters.Add(parameterPreviousId);
        SqlParameter parameterNextId = new SqlParameter("@NextId", System.Data.SqlDbType.Int)
        {
            Direction = System.Data.ParameterDirection.Output
        };
        cmd.Parameters.Add(parameterNextId);
        cmd.ExecuteNonQuery();
        if (parameterPreviousId.Value != DBNull.Value)
        {
            _PreviousId = Convert.ToInt32(parameterPreviousId.Value);
        }
        if (parameterNextId.Value != DBNull.Value)
        {
            _NextId = Convert.ToInt32(parameterNextId.Value);
        }
    }
}

Remember "null" is not the same as "DBNull"

When supplying null values to stored procedures, remember that you have to set the value to DBNull…

if (_UserId == null)
{
    cmd.Parameters.Add(new SqlParameter("@UserId",System.DBNull.Value ));
}
else
{
    cmd.Parameters.Add(new SqlParameter("@UserId", _UserId));
}