How to make a generic number parser in C#?
See the question and my original answer on StackOverflowActually, the standard number types do implement a common interface: IConvertible. This is the one that Convert.ChangeType
use.
Unfortunately, there is no TryParse
equivalent, it will throw exceptions if the string cannot be parsed.
As a side note, it seems this whole "conversion" area has been completely forgotten by the BCL team. There is nothing new there since .NET Framework 1 (except from TryParse methods).