2008-01-31

How NOT to find out if a given string is integer or not in C Sharp


To find out if a given string is integer or not in C Sharp use the Int32.TryParse() method. Returns a boolean value: if it is true then the string is recognized as an integer number, if it returns false then the conversion did not succeed.
All the other numeric types have a TryParse() method.

Do NOT use the methods discovered by this guy because to throw an exception takes time. Also his character iteration method is not useful if we would like to parse a negative integer or a number that contains thousand separators. (He claims to be a Microsoft certified Team Leaded. For crying out loud... I mean come on...)

Post a Comment