Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is System.Drawing.Color not an enum

Why is System.Drawing.Color a struct and System.ConsoleColor an enum ?

like image 776
Jan-Fokke Avatar asked Oct 08 '16 18:10

Jan-Fokke


2 Answers

Because the console only supports a small set of colours, whereas System.Drawing models all possible 24-bit colours (32-bit with alpha). That's over 4 billion possible colours, which would be a big enum!

Here are the console colours:

enter image description here

There are 16 foreground, plus 16 background colours.

Note that in System.Drawing some colours are given names, but they're not an enum -- they're static fields, such as Color.Red and Color.Aquamarine.

The same is true of System.Windows.Media.Color (as used in WPF).

like image 83
Drew Noakes Avatar answered Sep 28 '22 20:09

Drew Noakes


Because there are 16 well known colors for console, but 16777216 colors (plus 256 alpha levels for each) that can be used in general. Would you like to name all 4 billion of them and write code that then converts these enums back into actual RGBA values?

like image 29
Sami Kuhmonen Avatar answered Sep 28 '22 18:09

Sami Kuhmonen