Nullable Int32 Parse

Is it possible to parse a string into a Nullable Integer If the string can be parsed the Parse method would return an integer, if not it would return null.

Here is how I would expect it to work:
String s = "5";
Int32 i;
i = {Something}.Parse(s);

I have seen this question asked many times, but could not find an answer so I am guessing it cannot be done in v2.



Answer this question

Nullable Int32 Parse

  • Sasha

    You can write your own {Something}, it need only contain this method:


    public static int Parse(string s) {
        int i;
        if (int.TryParse(s, out i)) return i;
        else return null;
    }

     



  • Nullable Int32 Parse