C# Can';我的方法不能使用大写字符串数组
后面列出了整个程序,但我唯一的问题是C# Can';我的方法不能使用大写字符串数组,c#,loops,C#,Loops,后面列出了整个程序,但我唯一的问题是ToUppers()方法。我只希望这个方法迭代数组中的每个字符串,然后使所有内容都大写 private static string[] ToUppers(string[] stringToUpperArrays) { string stringer; foreach (string value in stringToUpperArrays) {
ToUppers()
方法。我只希望这个方法迭代数组中的每个字符串,然后使所有内容都大写
private static string[] ToUppers(string[] stringToUpperArrays)
{
string stringer;
foreach (string value in stringToUpperArrays)
{
stringer = value.ToUpper(); // <== this line highlighted
Console.WriteLine(stringer);
}
return stringToUpperArrays;
}
初始化阵列时,应擦除+1
stringArray = new string[(numInArray)];
用这种方法
private static string[] CreateArray(int numInArray)
在
CreateArray
中,您将数组定义为numInArray+1
的大小,但只能用numInArray
字符串填充数组,即最后一个索引为空。当您尝试value.ToUpper()时代码>在空索引上,您会得到异常
在CreateArray
中更改
stringArray = new string[(numInArray + 1)];
到
或改变
for (index = 0; index < numInArray; ++index)
{
Console.Write("Enter string #" + (index + 1) + " ");
stringArray[index] = Console.ReadLine();
}
for(索引=0;索引
到
for(索引=0;索引
这并不能回答问题
stringArray = new string[numInArray];
for (index = 0; index < numInArray; ++index)
{
Console.Write("Enter string #" + (index + 1) + " ");
stringArray[index] = Console.ReadLine();
}
for (index = 0; index < stringArray.Length; ++index)
{
Console.Write("Enter string #" + (index + 1) + " ");
stringArray[index] = Console.ReadLine();
}