I want to find the last character of a string and then put in an if
stating that if the last character is equal to \"A\", \"B\" or \"C\" then to do a certain action
string
is a zero based
array of char
.
char last_char = mystring[mystring.Length - 1];
Regarding the second part of the question, if the char is A
, B
, C
Using if statement
char last_char = mystring[mystring.Length - 1];
if (last_char == 'A' || last_char == 'B' || last_char == 'C')
{
//perform action here
}
Using switch statement
switch (last_char)
{
case 'A':
case 'B':
case 'C':
// perform action here
break
}