Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我试图按照用户随机输入的字母顺序排列字符串,但没有显示任何内容_C# - Fatal编程技术网

C# 我试图按照用户随机输入的字母顺序排列字符串,但没有显示任何内容

C# 我试图按照用户随机输入的字母顺序排列字符串,但没有显示任何内容,c#,C#,我试图使用String.Compare()方法来实现这一点,我的条件是,如果这些方法发现即将出现的单词按字母顺序排在当前单词后面,它们的位置会在临时字符串strWordTemp的帮助下发生变化 代码看起来很好,当到达最后一个数字时,我已经编写了另一段代码,以确保它与后面的单词进行比较,而不是与前面的单词进行比较。一切似乎都很好,但当我想展示这一点时,什么也看不出来。屏幕为空白,也不显示任何错误 for (int intI = 0; intI < strWordList.Length; in

我试图使用
String.Compare()
方法来实现这一点,我的条件是,如果这些方法发现即将出现的单词按字母顺序排在当前单词后面,它们的位置会在临时字符串
strWordTemp
的帮助下发生变化

代码看起来很好,当到达最后一个数字时,我已经编写了另一段代码,以确保它与后面的单词进行比较,而不是与前面的单词进行比较。一切似乎都很好,但当我想展示这一点时,什么也看不出来。屏幕为空白,也不显示任何错误

for (int intI = 0; intI < strWordList.Length; intI++)
{
    while (intI != strWordList.Length)
    {
        intComparison = string.Compare(strWordList[intI], strWordList[intI + 1]);
        if (intComparison > 0)
        {
            strWordTemp = strWordList[intI];
            strWordList[intI] = strWordList[intI + 1];
            strWordList[intI + 1] = strWordTemp;
        }
    }
    if (intI == strWordList.Length)
    {
        intComparison = string.Compare(strWordList[intI - 1], strWordList[intI]);
        if (intComparison > 0)
        {
            strWordTemp = strWordList[intI - 1];
            strWordList[intI - 1] = strWordList[intI];
            strWordList[intI] = strWordTemp;
        }
    }
}

for (int intI = 0; intI < strWordList.Length; intI++)
{
    System.Console.WriteLine("Word #" + (intI + 1) + " is: " + strWordList[intI]);
}
for(intinti=0;intI0)
{
strWordTemp=strWordList[intI];
strWordList[intI]=strWordList[intI+1];
strWordList[intI+1]=strWordTemp;
}
}
if(intI==strWordList.Length)
{
intComparison=string.Compare(strWordList[intI-1],strWordList[intI]);
如果(intComparison>0)
{
strWordTemp=strWordList[intI-1];
strWordList[intI-1]=strWordList[intI];
strWordList[intI]=strWordTemp;
}
}
}
for(int intI=0;intI
您的代码中有无限循环:

    while (intI != strWordList.Length)
    {
        intComparison = string.Compare(strWordList[intI], strWordList[intI + 1]);
        if (intComparison > 0)
        {
            strWordTemp = strWordList[intI];
            strWordList[intI] = strWordList[intI + 1];
            strWordList[intI + 1] = strWordTemp;
        }
    }

无论是
intI
还是
strWordList.Length
都不会在循环中更改,并且没有
break
语句,因此它将永远运行。

语法太相似了。。。这是哪种语言,C#还是Java?“尝试使用类似的代码,因为我的类不允许高级编码”--翻译:我将试着把你的工作当作我自己的,所以如果你能把它混合在一起,让我更容易,那将是非常棒的。@psubsee2003 oops。。。我猜是Java,没有想到C#…不,这绝对是C#
System.Console.WriteLine
在我的词典中不存在。@Makoto我对Java的了解还不足以确定这一点,但我认为确实如此。谢谢你的确认,汉克斯兄弟,有道理。我失去了常识。英雄联盟