Example. We use the Enum.GetNames method and the typeof operator along with the Where extension method. With Where, we remove Control colors from the output. Other articles describe these methods in depth.Enum.GetNameWhere
Tip: To compile the program, add the System.Drawing assembly to your project. When you execute it, all available colors will be printed to the Console.
And: It uses the StartsWith method and LINQ extension methods. These help generate the correct output.
C# program that generates HTML color table
static void Main()
// Get enum strings and order them by name.
// Remove Control colors.
foreach (string c in Enum.GetNames(typeof(KnownColor)).Where(
item => !item.StartsWith("Control")).OrderBy(item => item))
// Write table row.
Discussion. Sometimes we can create our documentation directly from the code and libraries we use. This is one example. The KnownColors can be enumerated and listed. This also helps us learn about how to use this programming language.
Summary. This table contains the KnownColors from the System.Drawing namespace. Next we saw the console program that generates the table. A color sheet can be useful for selecting named colors for Internet articles.