How do I create static instances of a class inside that class?
Posted
by
wehas
on Stack Overflow
See other posts from Stack Overflow
or by wehas
Published on 2011-03-20T19:03:16Z
Indexed on
2011/03/20
19:19 UTC
Read the original article
Hit count: 167
c#
I have a class Color that holds values for the red, green, and blue channels of a color. The class constructor lets you create a new color by specifying values for the three channels. However, for convenience, I would also like to have some "premade" colors available for the programmer. For example instead of having something like
DrawRectangle(new Color(1, 0, 0));
you would be able to say
DrawRectangle(Color.Red);
Where Color.Red is an instance of Color that lives inside the Color class. How can I declare these instances of Color inside the Color class? If there is a name for this type of technique I'd like to know it as I had no idea what search terms to use when I was looking for help online.
© Stack Overflow or respective owner