Method ToString
ToString(string?, IFormatProvider?)
Returns a string that represents the current object.
public string ToString(string? formatString, IFormatProvider? formatProvider = null)
Parameters
formatStringstringA format string that will be passed to Format(IFormatProvider, string, params object[]).
See remarks for parameters passed to that method.formatProviderIFormatProviderAn optional IFormatProvider to use when formatting the Color using custom format strings not specified for this method. Provides this instance as Argb.
See remarks for defined format strings.
If this parameter is not null, the specified IFormatProvider will be used instead of the custom formatting provided by the Color type.
Returns
- string
A string that represents the current object.
Remarks
Pre-defined format strings for this method, if a custom formatProvider is not supplied are:
Value-Result
- g or null or empty string General/default format - Returns a named Color if there is a match, or a 24-bit/3-byte/6-hex digit string in "#RRGGBB" format.
- G Extended general format - Returns a named Color if there is a match, or a 32-bit/4-byte/8-hex digit string in "#AARRGGBB" format.
- d Decimal format - Returns a 3-component decimal representation of the Color in "rgb(R,G,B)" format.
- D Extended decimal format - Returns a 4-component decimal representation of the Color in "rgba(R,G,B,A)" format.
If formatProvider is provided and is a non-null ICustomColorFormatter, the
following behaviors are available, for the specified values of formatString:
Value-Result
- null or empty string
Calls Format(string?, byte, byte, byte, byte) on the
provided
formatProviderwith the null string, and R, G, B, and A as typed arguments of type byte . - All other values
Calls Format<TArg0>(IFormatProvider, CompositeFormat, TArg0) with the provided
formatProviderandformatString(parsed as a CompositeFormat), with the value of Argb as the sole uint-typed argument.
ToString()
Converts the color to a string representation.
[Pure]
public override string ToString()
Returns
- string
The string representation of this value in #RRGGBB format.
Remarks
If the color is a named color, the name is returned. Otherwise, the color is returned as a hex string.
A (Alpha channel) is ignored and the returned string will not include it for this overload.