这里是我的代码与评论。所以我很难退出循环。我知道如果(contd = true)应该退出,但如果他们输入Y继续前进,我该如何回到循环中? 另一件事是如何按abc顺序排序。然后我怎么做Z-A的反向。感谢您的帮助,这里是无知的初学者。字符串数组以abc顺序排序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string lastName;
string [] lastName = new string[]; //array list of last names
int index;
string contd;
for (index=0;index++)
{
Console.Write("Enter a last name: ");
lastName[index] = Convert.ToString(Console.ReadLine());
Console.Write("Keep going? (Y/N): ");
//prompts user to keep inputting or exit out
contd = Convert.ToString(Console.ReadLine());
if (contd = "n"(Console.ReadLine());
{
//exit out of last name input
}
else contd = "y"(Console.ReadLine());
{
//go back into last name input
}
}
Console.WriteLine((index+1) + " last names entered");
//shows how many last names were entered
Console.WriteLine(); //spacing
//display last names
Console.WriteLine("Names in Acsending Order"); Console.WriteLine();
for(index=0; index++)
//shows the last names in order from A-Z (acsending)
{
Console.WriteLine(lastName[index]);
}
Console.WriteLine();
Console.WriteLine("Names in Descending Order"); Console.WriteLine();
for(index=0; index--)
//shows back last names in reverse order Z-A (descending)
{
Console.WriteLine(lastName[index]); Console.WriteLine();
}
Console.ReadLine();
}
}
}
'=='不是'=',作为一个方面说明,它真的很奇怪使用for循环作为一个while循环,如 – Sayse 2015-02-07 22:43:31
你应该问一个问题我。 – 2015-02-07 22:43:32
你真的*想'没有结束条件'循环吗?顺便提一句,“abc order”在英语中被称为“字母顺序”。 – 2015-02-07 22:46:24