Hi
how would you convert a String to Integer in unity csharp?
Hi
how would you convert a String to Integer in unity csharp?
int.Parse(string)
In C# it’s
System.Convert.ToInt32(“12345”);
Both ways are correct C# syntax, the more common practice in my experience is to use int.Parse(“”); but both are viable solutions.
both of the following will return the integer 12
int.Parse("12");
System.Convert.ToInt32("12");
If you are not guaranteed to get valid input (e.g., a user may input “asdf” instead of a number) you may also want to consider using the Int32.TryParse method instead.