You can also use if statements alone without adding the last else statement. You can also merge the else if statement.
Use if statements separately
Use if statements separately
1 if (condition) 2 { 3 (true); 4 }
Merge else if statement
1 string input; 2 input = (); 3 if (input == "") 4 { 5 ("You typed in an empty string"); 6 } 7 else if ( < 5) 8 { 9 ("The string had less than 5 characters."); 10 } 11 else if ( < 10) 12 { 13 ( "The string had at least 5 but less than 10 C haracters."); 14 }
The number of else if statements added to the if statement is not limited.Note that in the above example, a string variable input is declared for the user to enter text on the command line, fill the text into the input, and then test the length of the string variable. The code also shows how to do string processing in C#.