C# Example of Math Expressions, Variables, and If Statements

Anyone getting into C# and ASP.NET development will likely be starting with basic expressions, variables, and if statements. Get familiar with these concepts:

private void radioButton1_CheckedChanged(object sender, EventArgs e) 
    string x = this.textBox1.Text; 
    string y = this.textBox2.Text; 
    if (x == "") //See if x has no value 
        x = "0"; //Set x to 0 
    if (y == "") //See if x has no value 
        y = "0"; //Set y to 0 
    int x_number = Convert.ToInt32(x); //Converts the string x to a number then stores it in x_number 
    int y_number = Convert.ToInt32(y); 
    int random = x_number + y_number; //Sets the integer variable random to the value of x_number plus y_number 
    string random_string = Convert.ToString(random); //Converts the integer random to the string random_string 
    this.label3.Text = random_string; 
Posted In CategoriesC#, Reference| Tagged Tags