zoukankan      html  css  js  c++  java
  • 当使用Switch时 case太多,用委托代替

     switch (_mediaState)
                {
                    case State.Run:
                      AAA();
                        break;
                    case State.Stop:
                       BBB();
                        break;
                    case State.Forward:
                        CCC();
                        break;
                    case State.Rewind:
                        DDD();
                        break;
                }             
    public delegate void RelaceSwitch();
    private  static Dictionary<State,RelaceSwitch> ReplaceSwitch=new Dictionary<State, RelaceSwitch>();
    
            public static void MethodRun()
            {
                AAA();
            }
            public static void MethodStop()
            {
                BBB();
            }
            public static void MethodForward()
            {
                CCC();
            }
            public static void MethodRewind()
            {
                DDD();
            }
    
    
            private static void Adddic()
            {
                ReplaceSwitch.Add(State.Run, MethodRun);//ReplaceSwitch[State.Run]=MethodRun;
                ReplaceSwitch.Add(State.Stop, MethodStop);
                ReplaceSwitch.Add(State.Forward, MethodForward);
                ReplaceSwitch.Add(State.Rewind, MethodRewind);
            }
    
            private static void Exec(State state, RelaceSwitch action)
            {
                action.Invoke();
            }

    调用

    去掉switch

    首先Adddic();

    之后Exec(_mediaState, ReplaceSwitch[_mediaState]);

  • 相关阅读:
    as3 绕中心点旋转
    TweenMax
    As3支持的Html标签一览
    AS3.0 静音和停止所有声音
    as3 如何判断同时按下两个键
    前置窗体
    系统音效控制
    LocalConnection
    as3代码实现调用摄像头
    air 加载网页
  • 原文地址:https://www.cnblogs.com/dzh1990/p/8276053.html
Copyright © 2011-2022 走看看