using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;public enum Day : uint
{
Mon = 1, Tue = 2, Wed = 3, Thu = 4, Fri = 5, Sat, Sun
};
class EnumType
{
public static void Main(string[] args)
{
Console.WriteLine("ChooseDay(Day.Sun)");
Console.WriteLine("ChooseDay(Day.Mon)");
Console.ReadLine(); }
static string ChooseDay(Day d)
{
string tmp = "";
switch (d)
{
case Day.Mon:
tmp = string.Format("你选择一周中的{0}天(即周一),工作", (uint)d);
break;
case Day.Tue:
tmp = string.Format("你选择一周中的{0}天(即周二),工作", (uint)d);
break;
case Day.Wed:
tmp = string.Format("你选择一周中的{0}天(即周三),工作", (uint)d);
break;
case Day.Thu:
tmp = string.Format("你选择一周中的{0}天(即周四),工作", (uint)d);
break;
case Day.Fri:
tmp = string.Format("你选择一周中的{0}天(即周五),工作", (uint)d);
break;
case Day.Sat:
tmp = string.Format("你选择一周中的{0}天(即周六),工作", (uint)d);
break;
case Day.Sun:
tmp = string.Format("你选择一周中的{0}天(即周日),工作", (uint)d);
break;
default:
tmp = "不合法";
break; }
return tmp;
}
} 帮忙看下错在哪里谢谢~
using System.Collections.Generic;
using System.Linq;
using System.Text;public enum Day : uint
{
Mon = 1, Tue = 2, Wed = 3, Thu = 4, Fri = 5, Sat, Sun
};
class EnumType
{
public static void Main(string[] args)
{
Console.WriteLine("ChooseDay(Day.Sun)");
Console.WriteLine("ChooseDay(Day.Mon)");
Console.ReadLine(); }
static string ChooseDay(Day d)
{
string tmp = "";
switch (d)
{
case Day.Mon:
tmp = string.Format("你选择一周中的{0}天(即周一),工作", (uint)d);
break;
case Day.Tue:
tmp = string.Format("你选择一周中的{0}天(即周二),工作", (uint)d);
break;
case Day.Wed:
tmp = string.Format("你选择一周中的{0}天(即周三),工作", (uint)d);
break;
case Day.Thu:
tmp = string.Format("你选择一周中的{0}天(即周四),工作", (uint)d);
break;
case Day.Fri:
tmp = string.Format("你选择一周中的{0}天(即周五),工作", (uint)d);
break;
case Day.Sat:
tmp = string.Format("你选择一周中的{0}天(即周六),工作", (uint)d);
break;
case Day.Sun:
tmp = string.Format("你选择一周中的{0}天(即周日),工作", (uint)d);
break;
default:
tmp = "不合法";
break; }
return tmp;
}
} 帮忙看下错在哪里谢谢~
解决方案 »
- 问一个简单的算法 关于字符串的
- treeview??????????在线,急!!!!!!!!!!!
- 0001+1怎么才能等于0002啊?
- 怎样判断修改界面用户曾更改过数据
- 请问,如何将网页文件放到资源文件的包里,然后用webbrowser加载资源文件包里的网页?
- 【求助】用WinAPI SetParent的方法嵌入Excel到WinForm中后,Excel的标题栏和边框都没了
- c#调用VC++动态链接库
- 请问如何在Windows应用程序中方便的动态改变窗体上的控件?
- 做一个计时器
- ORA-010000:maximum open cursors exceeded?ADO.NET怎么关闭ORACLE游标?
- 接口问题
- WinFrom SqlConnection局域网连接
Console.WriteLine("ChooseDay(Day.Mon)");
这两句中的双引号是多余的
而且关于周几的枚举,.net类库本来就有:DayOfWeek.
Console.WriteLine(ChooseDay(Day.Sun));
Console.WriteLine(ChooseDay(Day.Mon));
Console.WriteLine(ChooseDay(Day.Mon));
C#里有DayOfWeek
得不到我要的结果啊,比如我输入1 得不到我第一天所要的答案啊~
也就是下面的switch语句没有执行啊!
Console.WriteLine(ChooseDay((Day)1));
也就是提示用户输入!
真不明白现在怎么那么多人连问题都不会问…… int input = 0;
while (input < 1 || input > 7)
{
Console.Write("请输入1---7:");
int.TryParse(Console.ReadLine(), out input);
}
Console.WriteLine(ChooseDay((Day)input));
跟你学了多少没有关系,不会就问是很正确的事情,但你要清楚地表达你要问什么问题,就拿你一开头那段代码来说,就说一个“帮忙看下错在哪里谢谢~”,谁知道你要干吗?到了第十楼才说“实际上我是想输入一个数,然后经过选择再输出下面的 switch中的语句!
也就是提示用户输入!”,那你说,我说你不会提问题有错吗
while (input < 1 || input > 7)
{
Console.Write("请输入1---7:");
int.TryParse(Console.ReadLine(), out day);
}
Console.WriteLine(ChooseDay((Day)day));
Console.WriteLine(ChooseDay((Day)day));
string.Format在这里的作用是什么?
(2) int.TryParse(Console.ReadLine(), out day);
TryParse这个转换是什么转换? 好了谢谢,暂时就这两个问题!
string.Format("你选择一周中的{0}天(即周五),工作", (uint)d); 表示将d的值填充到{0}这个位置
(2)int.TryParse是int的一个静态方法,用来将字符串转为int,如果转换成功,那么day就等于与字符串等价的int值
输出语句不是一般都用 Console.WriteLine(); 么?不能用Parse么? 他们的区别在哪里?
你只有提示,并没有去调用那个ChooseDay()方法。
static void Main(string[] args)
{
Console.WriteLine("ChooseDay(Day.Sun)");
Console.WriteLine("ChooseDay(Day.Mon)");
ChooseDay(int.Parse(Console.ReadLine()));
}
你只有提示,并没有去调用那个ChooseDay()方法。
static void Main(string[] args)
{
Console.WriteLine("ChooseDay(Day.Sun)");
Console.WriteLine("ChooseDay(Day.Mon)");
Console.WriteLine(ChooseDay(int.Parse(Console.ReadLine())));
}
Console.WriteLine 负责把最终的结果显示到 Console 中,而 Format 只是生成一个字符串,不负责输出Parse 的话,如果参数内容不对(比如给了个"abc"什么的)就会报错,导致程序不能继续运行;而 TryParse 比较温柔,参数内容不对只是返回 false ,让你可以比较从容地处理