In C#, how to check whether a string contains an integer?

c#, integer, parsing, string, tryparse

Solution

The answer seems to be just no.

Although there are many good other answers, they either just hide the uglyness (which I did not ask for) or introduce new problems (edge cases).

Problem

I just want to know, whether a String variable contains a parsable positive integer value. I do NOT want to parse the value right now. Currently I am doing: ``` int parsedId; if ( (String.IsNullOrEmpty(myStringVariable) || (!uint.TryParse(myStringVariable, out parsedId)) ) {//..show error message} ``` This is ugly - How to be more concise? Note: I know about extension methods, but I wonder if there is something built-in.

Original source