Tell me, is it possible to write a string to the? Int type without writing functions?

I tried to find solutions, but mostly I came across self-written transformation functions.

Is it really impossible to perform similar conversions with the C # tools?

    1 answer 1

    Try int.Parse . Or int.TryParse , if the string has the legal right to be a non-string representation of the number.

    Most likely, you will need a variant with the language : int.Parse(s, CultureInfo.InvatiantCulture) or int.TryParse(s, NumberStyles.Integer, CultureInfo.InvatiantCulture, out result) .

    For the case of a nullable type, if you need to get null in case of a conversion error, you will have to manually:

     int temp; int? result = int.TryParse(s, out temp) ? temp : default(int?);