Here is a small code snippet, which helps you toggle the string characters.
- string x="This is a String";
- string toggled= new string(x.Select(c => (char)(c > 64 && c < 91 ? c + 32 : (c>96 && c<123?c-32:c))).ToArray());
-
-
-
Explanation
Basically, I just selected character array and for each character, it checks whether it is falling under the range 65-90 (ASCII range for a-z) or 97-122 (ASCII range for A-Z).
Using ternery operator, I am adding the value to the ASCII value of the character and at the end, I am converting IEnumerable to Array and passing it to the string constructor.
Please let me know, if you have question or comments.