-2

I'm a comp sci student and have been given an assignment to create a c# console app which takes a hexadecimal value from the user and outputs the equivalent RGB value.

I'm very new to programming and so I've been struggling.

I've been trying to do it for hours and have got absolutely nowhere.

I've tried taking the hex value as a string from the user, then converting that string to an array of characters and replacing the letters with the appropriate numbers e.g. a would be 10, b to 11 etc. but kept receiving endless errors.

Can someone please point me in the right direction?

Thanks

Dylan
  • 1
  • 3
  • Giving this assignement to us won´t help you at all. Please write what you´ve tried, then we may help you with that specfic problem. But we don´t give you the ready to use solution for this. – MakePeaceGreatAgain Oct 30 '18 at 22:40
  • 1
    A big part of learning to program is learning to search effectively even when you're not sure what you're doing. From your question I searched for "hex to rgb c#" and found several results which looked promising. Including some [on](https://stackoverflow.com/questions/5735886/how-to-convert-hex-to-rgb) [this](https://stackoverflow.com/questions/5553673/how-to-convert-hexadecimal-color-to-rgb-color-24-bit) site.. – stuartd Oct 30 '18 at 22:46
  • 2
    `I've tried taking the hex value as a string from the user, then converting that string to an array of characters and replacing the letters with the appropriate numbers e.g. a would be 10, b to 11 etc. but kept receiving endless errors.` please show us the code, and the endless errors. Also, keep in mind that the pain you are feeling now **is the life of a programmer**. The fact that things aren't working, and you have to google and learn to make it work, isn't weird or an indicator that you are doing something wrong. It is literally what programming is. – mjwills Oct 30 '18 at 22:46
  • Supply the code for debugging and we will be able to provide constructive feedback. If you are getting into coding then be prepared to fix one error and have 2 more pop up. – Drew Oct 30 '18 at 23:49

1 Answers1

2

First add a reference to System.Drawing in your Console application. The following code demonstrates how to convert hex to RGB:

static void Main()
{
    string hex = "#FFFFFF";
    Color color = ColorTranslator.FromHtml(hex);
    Console.WriteLine("R: {0} G: {1} B: {2}", color.R, color.G, color.B);
    Console.ReadKey(true);
}
mr.coffee
  • 962
  • 8
  • 22