private void GetNames()
{
Color originColor = Color.FromArgb(255, 206, 206, 206);
// Simplest, but not necessary the best one
int Distance(Color left, Color right) =>
Math.Abs(left.R - right.R) +
Math.Abs(left.G - right.G) +
Math.Abs(left.B - right.B) +
Math.Abs(left.A - right.A);
var result = Enum
.GetValues<KnownColor>()
.MinBy(color => Distance(Color.FromKnownColor(color), originColor));
}
the error is on:
GetValues<KnownColor>
The non-generic method ‘Enum.GetValues(Type)’ cannot be used with type arguments
>Solution :
The type argument for Enum.GetValues was added in .NET 5, according to the documentation.
So, either upgrade your .NET version to .NET 5+, or pass it as a method parameter like this:
Enum.GetValues(typeof(KnownColor))
However, unlike the overload that accepts a type parameter, the above returns a generic array rather than an array of KnownColor, so you have to cast it.
var colors = (KnownColor[])Enum.GetValues(typeof(KnownColor))