实例代码如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace WebSites1
{
class Program
{
//Program entry
static int Main(string[] args)
{
string[] siteName = new string[6];
string phrase = "What is your pleasure";
string choice;
int count = 0;
//If there was a cmd line arg,use it;
if (args.Length == 0)
{
Console.WriteLine("{0},Master?",phrase);
}
else
{
Console.WriteLine("{0},{1}?",phrase,args[0]);
}
do
{
//Print menu.
Console.WriteLine("");
Console.WriteLine("A - Add Site");
Console.WriteLine("S - Sort List");
Console.WriteLine("R - Show Report \n");
Console.WriteLine("Q - Quit\n");
Console.WriteLine("Please Choose(A/S/R/Q): ");
choice = Console.ReadLine();
//Figure out what user wanted.
switch(choice)
{
//Add a site
case "a":
case "A":
Console.WriteLine("\nAdding Site\n");
string doAgain = "Y";
//Keep it up as long as user wants
while(doAgain.ToUpper() == "Y")
{
Console.Write(
"Please Enter Site Name: ");
siteName[count++]=Console.ReadLine();
Console.Write("Add Another?:");
doAgain=Console.ReadLine();
//There can _disibledevent= "Q");
return 0;
}
}
}