继续上面的学习,这次的是流程控制,用dowhile,代码如下,还是用语言选择来作为事例的。
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication9
{
class Program
{
static
void Main(
string [] args)
{
Console.WriteLine(
"欢迎进入语言选择:" );
string Language;
do
{
Console.WriteLine(
"==================>" );
Language = Console.ReadLine();
switch (Language)
{
case
"C" :
selectC();
break ;
case
"Delphi" :
selectDelphi();
break ;
case
"Java" :
selectJava();
break ;
default :
selectDefault();
break ;
}
}
while (Language!=
"exit" );
//这边的(!=)不能写成(<>),我第一次写的时候就习惯性写错了
}
private
static
int selectDelphi()
{
Console.WriteLine(
"你选择的是Delphi语言" );
return 0;
}
private
static
int selectJava()
{
Console.WriteLine(
"你选择的是Java" );
return 0;
}
private
static
int selectC()
{
Console.WriteLine(
"你选择的是C语言" );
return 0;
}
private
static
int selectDefault()
{
Console.WriteLine(
"你的选择只有三个:" );
Console.WriteLine(
"C" );
Console.WriteLine(
"Java" );
Console.WriteLine(
"Delphi" );
Console.WriteLine(
"exit为退出" );
Console.WriteLine(
"=================>" );
return 0;
}
}
}
转载于:https://blog.51cto.com/jayai/132252