Parsing hex numbers, and .NET class library discoverability.


Someone emailed me a question, asking how to convert a number
represented as a hexadecimal string into a number you can work with, so
I thought I'd post the answer here for Google to find.

  string hexNumber = "4000";
  int x = Int32.Parse(hexNumber, NumberStyles.HexNumber);
  Console.WriteLine(x);  // prints 16384

Quite often I find that discoverability in the framework isn't as good
as it could be because functionality related to one class is actually
provided as a static in another class. 

For example if you have an array of strings:

  string[] names = new string[42];

And you want to sort it, typing "names." won't find you the Sort
method.  You have to type "Array." to see the Array.Sort static
method.  A lot of handy functionality is provided this way, and is
very difficult to discover.

One class especially worth knowing is Convert.

Not that this has anything to with the question, but it's something
worth being aware of.  I've seen a few mentions recently of
'missing' functionality in the framework, that was actually there, but
not easy to find.