vs2010

C# 实验2 值类型的定义及使用


先上软件运行图

值类型的定义和使用

代码部分如下

Weekday.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WpfApplication1
{
    enum WeekDay {
        星期日,
        星期一,
        星期二,
        星期三,
        星期四,
        星期五,
        星期六,
        error
    }
}

WeekPrase.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WpfApplication1
{
    struct WeekPrase
    {
        public static string dayToWeek(int day)
        {
            string week;
            switch (day % 7)
            {
                case 0:
                    week = WeekDay.星期日.ToString(); break;
                case 1:
                    week = WeekDay.星期一.ToString(); break;
                case 2:
                    week = WeekDay.星期二.ToString(); break;
                case 3:
                    week = WeekDay.星期三.ToString(); break;
                case 4:
                    week = WeekDay.星期四.ToString(); break;
                case 5:
                    week = WeekDay.星期五.ToString(); break;
                case 6:
                    week = WeekDay.星期六.ToString(); break;
                default:
                    week = WeekDay.error.ToString(); break;
            }
            return week;
        }

        public static string enToChn()
        {
            string week;
            switch (DateTime.Now.DayOfWeek.ToString())
            { //获取当前为周几
                case "Sunday":
                    week = "星期日";  //转换为中文
                    break;
                case "Monday":
                    week = "星期一";
                    break;
                case "Tuesday":
                    week = "星期二";
                    break;
                case "Wednesday":
                    week = "星期三";
                    break;
                case "Thursday":
                    week = "星期四";
                    break;
                case "Friday":
                    week = "星期五";
                    break;
                case "Saturday":
                    week = "星期六";
                    break;
                default:
                    week = "格式错误";
                    break;
            }
            return week;  //返回结果
        }
    }
}

Window1.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            DayOfWeek.Text = WeekPrase.enToChn();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string week = DayOfWeek.Text;//今天
            int today = Convert.ToInt32(Enum.Parse(typeof(WeekDay), week));
            int pass = int.Parse(textBox2.Text);
            textBox3.Text = WeekPrase.dayToWeek(today + pass);
        }
    }
}
5 Responses Comment (5) Trackback (0)
  1. 水漾涟漪sily :

    :evil: 留言是种美德,写点什么…

  2. dang :

    :sad: 这个也要发吗?.

    1. SingleX Post author :

      @dang : 嘿嘿,纪念一下抓狂的VS :neutral:

  3. SingleX Post author :

    太TM简单了…… :wink: :wink:

发表评论