I try to add a method to the color class in C#
public static class ColorExtensions
{
public static System.Drawing.Color GrayTone(int Darkness)
{
return Color.FromArgb(255 - Darkness, 255 - Darkness, 255 - Darkness);
}
}
But I cannot use it like
Color MyColor = Color.GrayTone(80);
Using
public static class ColorExtensions
{
public static Color MakeBlack(this Color color)
{
return Color.Black;
}
}
Color Test = Color.Beige.MakeBlack();
works. How can I add the method GrayTone to the color class? I read Can I add extension methods to an existing static class? but unfortunately I cannot translate it into my Situation.