- 枚舉操作: GetNames(), CompareTo()...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class EnumApp
{
public enum Weekday
{
Sun, Mon, Tue, Wed, Thu, Fri, Sat
}
public static void Main()
{
Weekday wd1 = Weekday.Mon;
Console.WriteLine("每周的工作日从{0}开始", wd1);
Weekday wd2 = Weekday.Fri;
Console.WriteLine("到{0}结束", wd2);
Console.WriteLine("每周有{0}个工作日", wd2 - wd1 + 1);
Console.WriteLine();
Console.WriteLine("Mon之后是{0}", NextDay(Weekday.Mon));
Console.WriteLine();
foreach (string s1 in Weekday.GetNames(typeof(Weekday)))
{
Console.Write(s1 + " ");
}
Console.WriteLine("\n");
Console.Write("今天是星期几? ");
Weekday wd3 = (Weekday)Weekday.Parse(typeof(Weekday), Console.ReadLine());
Console.WriteLine("明天是{0}", NextDay(wd3));
Console.WriteLine();
Console.Write("体育课在星期几? ");
wd1 = (Weekday)Weekday.Parse(typeof(Weekday), Console.ReadLine());
Console.Write("物理试验在星期几? ");
wd2 = (Weekday)Weekday.Parse(typeof(Weekday), Console.ReadLine());
if (wd1.CompareTo(wd2) == 0)
{
Console.WriteLine("糟糕,在同一天。");
}
else
{
Console.WriteLine("没事,不在同一天");
}
}
public static Weekday NextDay(Weekday wd)
{
Weekday wdnext;
if (wd == Weekday.Sat)
return wdnext = Weekday.Sun;
else
return wdnext = ++wd;
}
}
}
As the plugin is integrated with a code management system like GitLab or GitHub, you may have to auth with your account before leaving comments around this article.
Notice: This plugin has used Cookie to store your token with an expiration.