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;
}