Most Efficient Way to Test Object Type *

Question

I have values stored as strings in a DataTable where each value could really represent an int, double, or string (they were all converted to strings during an import process from an external data source). I need to test and see what type each value really is.

What is more efficient for the application (or is there no practical difference)?

  1. Try to convert to int (and then double). If conversion works, the return true. If an exception is thrown, return false.
  2. Regular expressions designed to match the pattern of an int or double
  3. Some other method?

Answer

Would use double.TryParse, it has performance benefits.

< br > via < a class="StackLink" href=" http://stackoverflow.com/questions/1995/" >Most Efficient Way to Test Object Type< /a>
Share on Google Plus

About Cinema Guy

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment