Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here are the console color hex values, as converted by .NET 4.5. First the program:</p> <pre><code>using System; using System.Drawing; class Program { static void Main(string[] args) { foreach (var n in Enum.GetNames(typeof(ConsoleColor))) Console.WriteLine("{0,-12} #{1:X6}", n, Color.FromName(n).ToArgb() &amp; 0xFFFFFF); } } </code></pre> <p>And here's the output. As you can see, there's a problem with the reporting for <code>DarkYellow</code>. The full 32-bits of that one show up as zero. All the others have 0xFF for the alpha channel.</p> <pre><code>Black #000000 DarkBlue #00008B DarkGreen #006400 DarkCyan #008B8B DarkRed #8B0000 DarkMagenta #8B008B DarkYellow #000000 &lt;-- see comments Gray #808080 DarkGray #A9A9A9 Blue #0000FF Green #008000 Cyan #00FFFF Red #FF0000 Magenta #FF00FF Yellow #FFFF00 White #FFFFFF </code></pre> <p>edit: I got a little more carried away just now, so here's a converter from <code>RGB</code> to the nearest <code>ConsoleColor</code> value. Note that the dependency on <code>System.Windows.Media</code> is only for the demonstration harness; the actual function itself only references <code>System.Drawing</code>.</p> <pre><code>using System; using System.Windows.Media; class NearestConsoleColor { static ConsoleColor ClosestConsoleColor(byte r, byte g, byte b) { ConsoleColor ret = 0; double rr = r, gg = g, bb = b, delta = double.MaxValue; foreach (ConsoleColor cc in Enum.GetValues(typeof(ConsoleColor))) { var n = Enum.GetName(typeof(ConsoleColor), cc); var c = System.Drawing.Color.FromName(n == "DarkYellow" ? "Orange" : n); // bug fix var t = Math.Pow(c.R - rr, 2.0) + Math.Pow(c.G - gg, 2.0) + Math.Pow(c.B - bb, 2.0); if (t == 0.0) return cc; if (t &lt; delta) { delta = t; ret = cc; } } return ret; } static void Main() { foreach (var pi in typeof(Colors).GetProperties()) { var c = (Color)ColorConverter.ConvertFromString(pi.Name); var cc = ClosestConsoleColor(c.R, c.G, c.B); Console.ForegroundColor = cc; Console.WriteLine("{0,-20} {1} {2}", pi.Name, c, Enum.GetName(typeof(ConsoleColor), cc)); } } } </code></pre> <p>The output (partial)...</p> <p><img src="https://i.stack.imgur.com/I5jIQ.png" alt="test output"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload