Yes, using the appropriate TryParse method and ignoring the out parameter is the best way to do this.
You can wrap this in your own set of helper methods (which can indicate the appropriate culture, etc., if not suitable for you by default) and just return the bool without the out parameter to make it easier to call them.
Of course, you need to figure out which type of parsing is most appropriate - even for integers, you need to consider whether the Int32 range is enough for your use case. In my experience, most numerical inputs have their own βnaturalβ range of permissible values, which is unlikely to exactly match the range of any predefined type. Therefore, you can extend your helper methods to include a range of valid values ββfor adoption.
source share