- //方法1
- public string ToggleCase(string input)
- {
- string result = string.Empty;
- char[] inputArray = input.ToCharArray();
- foreach (char c in inputArray)
- {
- if (char.IsLower(c))
- result += c.ToString().ToUpper();
- else if (char.IsUpper(c))
- result += c.ToString().ToLower();
- else
- result += c.ToString();
- }
- return result;
- }
- //方法2
- public string ToggleCase(string input)
- {
- string result = string.Empty;
- char[] inputArray = input.ToCharArray();
- foreach (char c in inputArray)
- {
- if (char.IsLower(c))
- result += Char.ToUpper(c);
- else
- result += Char.ToLower(c);
- }
- return result;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1704201512280.html
来源: http://www.codesnippet.cn/detail/1704201512280.html