x

开发者

c# .net

导航

数组排序将111001000011排序到数组中list[0]=1,list[1]=1..........

       /// <summary>
        /// 数组排序将111001000011排序到数组中list[0]=1,list[1]=1..........
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string[] GetList(string str)
        {
            List<string> strList = new List<string>();
            for (int i = 0; i <= str.Length - 1; i += 1)
            {
                strList.Add(str.Substring(i, 1));
            }
            if (str.Length % 1 != 0)
            {
                strList.Add(str.Substring(str.Length - str.Length % 1));
            }
            return strList.ToArray();
        }
        /// <summary>
        /// 将DO1事件复选排列到数组中
        /// </summary>
        /// <returns></returns>
        private CheckBox[] InitiCheckList()
        {
            CheckBox[] check = new CheckBox[32];
            try
            {
                  check[0] = this.DO1_Event0;
                  check[1] = this.DO1_Event1;
                  check[2] = this.DO1_Event2;
                  check[3] = this.DO1_Event3;
                  check[4] = this.DO1_Event4;
                  check[5] = this.DO1_Event5;

                  check[6] = this.DO1_Event6;
                  check[7] = this.DO1_Event7;
                  check[8] = this.DO1_Event8;
                  check[9] = this.DO1_Event9;
                  check[10] = this.DO1_Event10;

                  check[11] = this.DO1_Event11;
                  check[12] = this.DO1_Event12;
                  check[13] = this.DO1_Event13;
                  check[14] = this.DO1_Event14;
                  check[15] = this.DO1_Event15;

                  check[16] = this.DO1_Event16;
                  check[17] = this.DO1_Event17;
                  check[18] = this.DO1_Event18;
                  check[19] = this.DO1_Event19;

                  check[20] = this.DO1_Event20;
                  check[21] = this.DO1_Event21;
                  check[22] = this.DO1_Event22;
                  check[23] = this.DO1_Event23;

                  check[24] = this.DO1_Event24;
                  check[25] = this.DO1_Event25;
                  check[26] = this.DO1_Event26;
                  check[27] = this.DO1_Event27;

                  check[28] = this.DO1_Event28;
                  check[29] = this.DO1_Event29;
                  check[30] = this.DO1_Event30;
                  check[31] = this.DO1_Event31;
                  
            }
            catch (Exception)
            {
                MessageBox.Show("超出索引");
            }
            return check;        
        }       
        /// <summary>
        /// 获取DO1事件,降序排列字符串
      /// </summary>
        private void GetCheckedDO1_Event()
        {
            try
            {
                string conversion = null;                  
                string show = Convert.ToString(UInt32.Parse(label1.Text), 2);
                for (int j = show.Length - 1; j >= 0; j--)
                {
                    conversion = conversion + show.Substring(j, 1);
                }
                for (int i = 0; i < conversion.Length; i++)
                {
                    if (conversion[i].ToString() == "1")
                    {
                        InitiCheckList()[i].Checked = true;
                    }
                    else
                    {
                        InitiCheckList()[i].Checked = false;
                    }
                } 
                //for (int i = 0; i < show.Length; i++)
                //{
                //    if (show[i].ToString() == "1")
                //    {
                //        InitiCheckList()[i].Checked = true;
                //    }
                //    else
                //    {
                //        InitiCheckList()[i].Checked = false;
                //    }
                //}            
               
            }
            catch(Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

 

posted on 2013-05-10 09:12  开发模式  阅读(192)  评论(0编辑  收藏  举报

x