zoukankan      html  css  js  c++  java
  • 一個簡單的排班方法

    目的:排出 2010年1~12月的A.P.N排班記錄 

    void Main()

    {
    IList<Schedule> schedules = new List<Schedule>();
    int year = 2010;
    int[] months = {1,2,3,4,5,6,7,8,9,10,11,12};
    foreach(int i in months){
    int maxDays = DateTime.DaysInMonth(year, i);
    for(int j=1; j<=maxDays; j++){
    foreach(string n in Enum.GetNames(typeof(ScheduleMode))){
    schedules.Add(new Schedule(){
    Year = year,
    Month = i,
    Date = j,
    Mode = (ScheduleMode)Enum.Parse(typeof(ScheduleMode), n),
    Description = string.Format("Work on {3}, {0}/{1}/{2}", year,i,j, new DateTime(year,i,j).DayOfWeek)
    });
    }
    }
    }
    schedules.Dump();
    }

    // Define other methods and classes here
    public enum ScheduleMode {
    A,P,N
    }
    public class Schedule{
    public int Year {get;set;}
    public int Month {get;set;}
    public int Date {get;set;}
    public ScheduleMode Mode {get;set;}
    public string Description {get;set;}
    }

    //////////////////////////////////////////////////////////////////////////////////////

     這裏隱含了另一個功能,可以通過Enum.GetNames(typeof(ScheduleMode))獲得枚舉類型的各項名稱(用於綁定到UI界面),還可以通過(ScheduleMode)Enum.Parse(typeof(ScheduleMode), n)將某個字符串轉換成枚舉類型(用於從數據庫查詢到的值轉換成枚舉類型),這樣我們就可以很方便地將數據庫中的查詢到的值轉換成“預先”定義好的枚舉類型(可以有“名稱”和“值”)。

  • 相关阅读:
    Java多线程问题
    pattern-matching as an expression without a prior match -scala
    从Zero到Hero,OpenAI重磅发布深度强化学习资源
    What-does-git-remote-and-origin-mean
    flink source code
    如何生成ExecutionGraph及物理执行图
    rocketmq 源码
    Flink source task 源码分析
    flink 获取上传的Jar源码
    fileupload
  • 原文地址:https://www.cnblogs.com/Koy/p/1784063.html
Copyright © 2011-2022 走看看