C#用switch编程
提示:输入Y(继续),输入Q(退出),输入R(重复),输入其它字符(无效)
using System;
using System.Collections.Generic;
using System.Text;
namespace homework1
{
class Program
{
public static void Main()
{
Letters = Convert.ToChar(Console.ReadLine());
switch (Letters)
{
case 4 :
}
}
}
}
刚开始这样我是知道的,但是到了后面我改了很多次还是不行,希望会的人能教教我
补充:格式怎么样我是知道,就是写不好
答案:public static void Main()
{
char Letters = 'Y';
while (1 == 1)
{
Letters = Convert.ToChar(Console.Read());
if (Letters != 'Y' && Letters != 'Q' && Letters != 'R')
{
continue;
}
switch (Letters)
{
case 'Y':
Console.WriteLine("继续");
break;
case 'Q':
return;
case 'R':
Console.WriteLine("重复");
break;
}
}
}
switch(Letters)
{
case 'Y':继续;break;
case 'Q':退出;break;
case 'R':重复;break;
default:输入无效;
}
其中中文部分为自己的函数或者语句
switch(内容)
{
case 内容:代码
default: 代码
}
public static void Main()
{
string inputstr = Console.ReadLine();
if(inputstr.Length == 0) return;
switch(inputstr.Substring(0,1).ToLower())
{
case "y":
break;
case "q":
break;
case "r":
break;
}
}
class Program
{
static void Main(string[] args)
{
Program obj = new Program();
obj.Funcation(Console.ReadLine());
}
public void Funcation(string str)
{
switch(str.Substring(0.1).ToUpper())
{
case "Y":
调用继续的方法;
break;
case "Q":
调用退出的方法;
break;
case "R":
调用重复的方法;
break;
default:
调用无效的方法;
break;
}
}
//另写四方法
}
上一个:IC读卡C#编程用到的第三方空间是Mwic_32.dll吗,它怎么用
下一个:C#网页编程的问题01