CurrentState是什么东,如果要转为指定类型
stateList[1] as xxxx

解决方案 »

  1.   

            public IState CurrentState;        public StateManager()
            {
                this.stateList = new List<IState>()
               {
                    new SettingState(),
                    new CountUpState(),
                    new StopState(),
                    new CountDownState()
                 
               };        }
      

  2.   

    我这样做了
                for (int i = 0; i < stateList.Count; i++)
                {
                    if (this.Mode.ToString() == stateList[i].state)
                    {
                        return stateList[i];
                    }
                }
      

  3.   

    你的程序设计有问题
    你想判断当前的CurrentState的类型是否是某个对象的类型,如果是的话就转成那个类型
    为什么要这么做啊?
      

  4.   

    Type type = list.GetType().GetGenericArguments()[0];
    只要判断一次就可以了。