Convert RGB To Integer In C#

If you ever wanted to convert an RGB value to an integer value, this is how you do it.
First strip the leading pound sign(#) from the string using the Substring function.

   string val = "#060810";
   var    rgb = val.Substring(1, val.Length -1);

Next split the string into 3 different parts representing red, green, and blue

   var r = int.Parse(rgb.Substring(1, 2), NumberStyles.HexNumber);
   var g = int.Parse(rgb.Substring(3, 2), NumberStyles.HexNumber);
   var b = int.Parse(rgb.Substring(5, 2), NumberStyles.HexNumber);

*NB: The int.Parse function along with NumberStyle.HexNumber is used to convert each Hex number to its equivalent decimal representation, happy coding 🙂