Search code examples
c#.netdebuggerdisplay

DebuggerDisplay - type in square brackets


class A
{
    public Color ColorA { get; set; }
    public Color ColorB { get; set; }

    public A(Color colorA, Color colorB)
    {
        ColorA = colorA;
        ColorB = colorB;
    }

    public override string ToString()
    {
        return ColorA + " " + ColorB;
    }
}

This renders as:

enter image description here


And this:

class A
{
    public Color ColorA { get; set; }
    public Color ColorB { get; set; }

    public A(Color colorA, Color colorB)
    {
        ColorA = colorA;
        ColorB = colorB;
    }

    public override string ToString()
    {
        return "Red" + " " + "Black";
    }
}

renders as:

enter image description here

Why the difference?

Edit: I know why the difference. My question is, how to achieve second result without hardcoding the text of the color.


Solution

  • Try this:

    return ColorA.Name + " " + ColorB.Name;