Ask coding questions

← Back to all posts
How do I convert a numerical string to int in C#?
awesome10 (217)

Recently, I've been attempting to learn C#, but I can't find a working way to convert an string to an int, please help

Answered by Coder100 (6600) [earned 5 cycles]
View Answer
Coder100 (6600)

Hello, you are in luck! The process is quite easy.


string number;
int converted;
number = "50";
converted = int.Parse(number);

Note: It is HIGHLY recommended that you sanitize user input before doing this! C# is very sensitive to spaces and non-numerical characters.

Please mark as correct answer if it has helped you!

awesome10 (217)

@Coder100 oh ok, thank you so much, I thought it would have something to do with 2 variables thanks again!