zoukankan      html  css  js  c++  java
  • Dictionary的用法!

    1、使用方法简单,配合枚举一起使用,主要介绍Dictionary的使用和取值,本人感觉他用在项目固定状态值搭配使用,这样能做到项目最大重用,而且代码方便管理,具体使用代码如下

        声明枚举变量:

        /// <summary>
    /// 试卷状态
    /// </summary>
    public enum DraftPaperState
    {
    Closed = 0,//关闭
    Edit = 1,//编辑中
    Release = 2//发布
    }

       向集合中添加值:

            /// <summary>
    /// 试卷状态
    /// </summary>
    /// <returns></returns>
    public static Dictionary<DraftPaperState, string> GetDraftPaperState()
    {
    if (_DraftPaperState == null)
    {
    _DraftPaperState = new Dictionary<DraftPaperState, string>();
    _DraftPaperState.Add(DraftPaperState.Closed, "关闭");
    _DraftPaperState.Add(DraftPaperState.Edit, "编辑中");
    _DraftPaperState.Add(DraftPaperState.Release, "发布");
    }
    return _DraftPaperState;
    }

      界面中使用:

     Dictionary<DraftPaperState, string> draft = Enums.GetDraftPaperState();
    foreach (KeyValuePair<DraftPaperState, string> draftPaperState in draftPaperStates)
    {
    if ((int)draftPaperState.Key == “aaa”)
    {
    string keyValue= draftPaperState.Value;
    }
    }

    相信你会使用了吧,那就尝试一下吧!如有不尽人意地方,欢迎纠正。

  • 相关阅读:
    nginx日志
    silverlight 双击事件
    Silverlight button 图片切换样式
    Caliburn.Micro学习笔记(一)----引导类和命名匹配规则
    关闭Outlook时最小化 dll
    wpf键盘记录器
    WPF之TreeList的实现方法(一)
    精典算法之详解 河内之塔
    精典算法之二分查找法
    指针数组和数组指针
  • 原文地址:https://www.cnblogs.com/BeyondWJsel/p/2411755.html
Copyright © 2011-2022 走看看