0
Help please (I dont get it)
https://edabit.com/challenge/99oN5igrbXddAjHEL why does it work this way: public static string ReverseCase(string str) { str.ToCharArray(); for (int i = 0; i < str.Length; i++) { ///////////this part is the important////////////// if (char.IsUpper(str[i])) { char.ToLower(str[i]); } else { char.ToUpper(str[i]); } ///////////////////////////////// } return str.ToString(); } } but not this way: char.IsUpper(str[i]) ? char.ToLower(str[i]) : char.ToUpper(str[i]);
1 Answer
+ 3
static string ReverseCase(string str) {
Char[] chars = str.ToCharArray();
for (int i = 0; i < chars.Length; ++i) {
chars[i] = Char.IsUpper(chars[i])? Char.ToLower(chars[i]):Char.ToUpper(chars[i]);
}
return new String(chars);
}
static void Main(string[] args) {
string str = "HelLo, WoRlD";
str = ReverseCase(str);
Console.WriteLine(str);
}
Ternary operator needs to be used as an rvalue.