C# cast to int code example
Example 1: string to int c#
int x = Int32.Parse("1234");
Example 2: parsing string to int c#
string userInput = Console.ReadLine();
int convert;
Int32.TryParse(userInput, out convert);
Example 3: convert string to number C#
int x = 0;
Int32.TryParse(TextBoxD1.Text, out x);
Example 4: convert string to int c#
Int16.Parse("100");
Int16.Parse("(100)", NumberStyles.AllowParentheses);
int.Parse("30,000", NumberStyles.AllowThousands, new CultureInfo("en-au"));
int.Parse("$ 10000", NumberStyles.AllowCurrencySymbol);
int.Parse("-100", NumberStyles.AllowLeadingSign);
int.Parse(" 100 ", NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite);
Int64.Parse("2147483649");
Example 5: c# string to int
string input = Console.ReadLine();
int X = int.Parse(input);
Console.WriteLine(X);
Example 6: c# type conversion
float varFloat = 12.7f;
double varDouble = varFloat;
double varDouble = 2.3;
int varInt = (int) varDouble;
int varInt = 19;
string varString = varInt.ToString();
string varString = "89";
int varInt = int.Parse(varString);
double varDouble = double.Parse(varString);
int varInt = Convert.ToInt32(varString);
double varDouble = Convert.ToDouble(varString);