Search code examples
c#multidimensional-arraynullablexml-comments

XML Comments for nullable 2D Array


How do I correct specify the XML Comments for a 2D array of nullable doubles? The following gives me syntax error.

/// <returns>The <see cref="double[,]"/>.</returns>
public double?[,] Get2DArray()
{
    ...
}

If it was just a 2D array of doubles I'd use:

/// <returns>The <see cref="double{T,T}]"/>.</returns>
public double[,] Get2DArray()
{
    ...
}

and if was just a single value I'd use:

/// <returns>The <see cref="Nullable{Double}"/>.</returns>
public static double? GetNullableDouble()
{

I can't seem to combine these two concepts to get the correct comments.


Solution

  • After reading here, perhaps you want,

    /// <summary>
    /// Gets the 2D Array
    /// </summary>
    /// <returns>The <see cref="T:double?[,]"/>.</returns>
    public double?[,] Get2DArray()
    {
        ...
    }
    

    As commented, rather than a multi-dimensional array (double?[,]) you should consider something jagged, the internal .Net implementation is superior. Additionaly, if you think of interfaces as promises, you should make the smallest possible promise, they are easier to keep.

    Perhaps,

    /// <summary>
    /// Gets the 2D Array
    /// </summary>
    /// <returns>
    /// The <see cref="T:IEnumerable{IEnumerable{double?}}"/> data.
    /// </returns>    
    public IEnumerable<IEnumerable<double?>> GetData()
    {
        ...
    }
    

    would suffice.