专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »DotNet » 循环语句:在C#中使用语句和循环来控制程序流总程序 »正文

循环语句:在C#中使用语句和循环来控制程序流总程序

来源: 发布时间:星期三, 2008年9月10日 浏览:119次 评论:0

实例代码如下:

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;
}
}
}

0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: