Int32.TryParse() returns zero on failure - success or failure?

后端 未结 5 1640
萌比男神i
萌比男神i 2021-01-01 09:06

I read this from msdn about Int32.TryParse()

When this method returns, contains the 32-bit signed integer value equivalent to the num

5条回答
  •  情深已故
    2021-01-01 09:41

    using C# 7 now you can declare the variable within the TryParse like ...

    if (Int32.TryParse(someText, out int value))
    {
       // Parse successful. value can be any integer
    }
    else
    {
       // Parse failed. value will be 0.
    }
    

提交回复
热议问题