如何高效判断ArrayList中是否含有某字符串呢?或者能否判断最长的一行的长度呢?

解决方案 »

  1.   

    if (ArrayList1.IndexOf("OK") > -1)
    {
    console.writeline("找到了");
    }
    ========================有没有类似的indexof方法呀,我好放if里判断
      

  2.   

    VS2005以前的
            private void button2_Click(object sender, EventArgs e)
            {
                ArrayList _Test = new ArrayList();            _Test.Add(button1);
                _Test.Add("123123");
                _Test.Add("12312322222222222");            this.Text = GetMaxLength(_Test).ToString();
            }
            public int GetMaxLength(ArrayList p_List)
            {
                int _Length = 0;
                foreach (object _Obj in p_List)
                {
                    string _Value = _Obj as string;                if (_Value != null && _Value.Length > _Length) _Length = _Value.Length;
                }
                return _Length;
            }
    如果是2008可以 public static class MaxArray
        {
            public static int GetMaxLength(this ArrayList p_List)
            {
                int _Length = 0;
                foreach (object _Obj in p_List)
                {
                    string _Value = _Obj as string;                if (_Value != null && _Value.Length > _Length) _Length = _Value.Length;
                }
                return _Length;
            }    
        }ArrayList.GetMaxLength() 就可以了.
      

  3.   

    string tmpstr = "";                   
     foreach (object aa in arraylist1)
    {tmpstr += aa.ToString();
     }
    if (tmpstr.IndexOfOK") > 0)
    {
    console.writeline("找到了"); }=====================================
    这是我自己写的呵呵哪种方法效率高呀?