How to use TypeConverter

   TypeConverter typeconv= TypeDescriptor.GetConverter(typeof(int));

   Console.WriteLine(typeconv.IsValid("@@ASDF@#R53456+4A"));
   Console.WriteLine(typeconv.IsValid("123"));
   Console.WriteLine(typeconv.IsValid("12344"));
   Console.WriteLine(typeconv.IsValid("99999999999999999999999999999999999999999999999999999999999"));

Why all result is return true




Answer this question

How to use TypeConverter

  • Arne2503

    Hello.

    This is not error. Basically it checks only type of the argument. String is valid for conversion so this method returns true.

    If you want safely convert from string to integer you must wrap int.Parse() in try...catch section or if you use FM2.0 use int.TryParse()


  • How to use TypeConverter