using System;
using System.Numerics;
using System.Text;
class MyClass {
static void Main(string[] args) {
string str;
char[] str1=str.ToCharArray();
foreach (char c in inputArray)
{
if (char.IsLower(c))
str += char.ToUpper(c);
else
str += char.ToLower(c);
}
System.Console.WriteLine("str");
}
}
错误:tmp / CSHARP_30f1_944d_bf85_a405_1481953523 / editor_source_509c_cad9_9662_9111_1481953523.cs(8,23):错误CS0103:当前上下文中不存在名称`inputArray'编译失败:1个错误,0个警告
答案 0 :(得分:1)
试试这段代码,为了获得性能,你应该使用StringBuilder类:
using System.Text;
public class MyClass {
public static void Main(string[] args) {
string input="AbCdEf";
StringBuilder s1 = new StringBuilder();
foreach(char c in input){
if(char.IsLower(c)){
s1.Append(char.ToUpper(c));
}else{
s1.Append(char.ToLower(c));
}
}
System.Console.WriteLine(s1.ToString());
}
}
答案 1 :(得分:0)
使用System.Linq
string input = "AAaaBBccDe";
var result = new String(input.Select(x => char.IsLower(x) ? char.ToUpper(x) : char.ToLower(x)).ToArray());