This should be a simple one but I’m looking for the best answer with at least some regard for performance as well as elegance.
I have a list of strings and some of the values are of the form q1, q2, q3 etc.
I’d like to select these.
What would be the best method of doing this?
Seems like you’re trying to microoptimize, which means you’ll spend a lot of effort to make your program run the same speed. Focus on clarity of code first, and then optimize what is actually slow.
Assuming you have profiled and found this to be your application’s bottleneck in real-world scenarios:
It is inelegant (and often a performance drag) to use exceptions in non-exceptional cases. See http://www.developerfusion.com/code/4650/validating-an-integer/, for example.
Depending on the constraints of your situation, you’re probably better off changing your
IsInteger()to do one of:(See http://msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx)
or:
(See http://www.hanselman.com/blog/ExploringIsNumericForC.aspx)
or
And then: