【发布时间】:2014-03-21 08:32:49
【问题描述】:
我的代码翻转了一个单词,它可以工作但显示此错误:
参数超出范围异常未处理
strFlippedWord = strUserWord.Sub... 行显示错误
string strUserWord;
string strFlippedWord;
int intWordLength;
System.Console.WriteLine("Please enter a word to flip: ");
strUserWord = System.Console.ReadLine();
intWordLength = strUserWord.Length;
while (intWordLength != -1)
{
strFlippedWord = strUserWord.Substring(intWordLength - 1, 1);
System.Console.Write(strFlippedWord);
intWordLength -= 1;
}
System.Console.ReadKey();
【问题讨论】:
-
您是否要反转字符串,即“abc”->“cba”?