当前位置:编程学习 > asp >>

如何通过key获取value值,键找值!多线程单利模式

模拟微软风格的写法,语义极其清晰,上代码
    public partial class ProsessApprove : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ProcessDesignStatusEnum status = new ProcessDesignStatusEnum();
            string key = status.未提交.key;
            string value = status.未提交.value;

            string value01 = status.ConvertKeyToValue.SetKey(1);//通过key获取值
        }
    }

上面的这是使用
如何定义直接看下面的代码
namespace CPACN_Collaboration.uImproving.ProcessDesign
{
    public abstract class BaseStatus
    {
        public string[,] arr = new string[5, 2];

        public BaseStatus()
        {
            arr[0, 0] = "未提交";
            arr[0, 1] = "1";
            arr[1, 0] = "待确认";
            arr[1, 1] = "2";
            arr[2, 0] = "已确认";
            arr[2, 1] = "3";
            arr[3, 0] = "待部署";
            arr[3, 1] = "4";
            arr[4, 0] = "待部署";
            arr[4, 1] = "5";
        }

        public string SetKey(int key)
        {
            if (key >= 5 || key <= 1)
            {
                return "错误的状态";
            }
            return arr[key - 1, 0];
        }
    }

    public class MethodClass
    {
        public class 未提交 : BaseStatus
        {
            private static 未提交 instance;
            private static object _lock = new object();
            private 未提交()
            {
           
            }
            public static 未提交 GetInstance()
            {
                if (instance == null)
                {
                    lock (_lock)
                    {
                        if (instance == null)
                        {
                            instance = new 未提交();
                        }
                    }
                }
                return instance;
            }

            public string value
            {
                get { return base.arr[0, 0]; }
            }

            public string key
            {
                get { return base.arr[0, 1]; }
            }
        }

        public class 待确认 : BaseStatus
        {
            private static 待确认 instance;
            private static object _lock = new object();
            private 待确认()
            {
           
            }
            public static 待确认 GetInstance()
            {
                if (instance == null)
                {
                    lock (_lock)
                    {
                        if (instance == null)
                        {
    &nb

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,