Help please (I dont get it) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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]);

1st Jun 2020, 10:02 PM
Michael
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.
2nd Jun 2020, 12:53 AM
ChaoticDawg
ChaoticDawg - avatar