《零基础学C#》第七章-实例03:星期颜色判断——练习1

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wtxhai/article/details/88786180
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Example703_01
{
    class UI//定义用户界面类
    {
        static UI()//定义静态构造函数
        {
            DateTime week = DateTime.Now;//记录当前时间
            //判断是否是周六、周日
            if (week.DayOfWeek == DayOfWeek.Saturday || week.DayOfWeek == DayOfWeek.Sunday)
            {
                Console.BackgroundColor = ConsoleColor.Green;//设置颜色为绿色
            }
            else
            {
                Console.BackgroundColor = ConsoleColor.Red;//设置颜色为红色
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            UI ui = new UI();//使用默认构造函数创建UI类的对象
            Console.ReadLine();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/wtxhai/article/details/88786180