ArrayList arr = new ArrayList();
arr.Add("a");
arr.Add("b");
arr.Add("c");不用循环得到字符串“abc”注:string.Concat(arr.ToArray()) 使用了循环

解决方案 »

  1.   


        class Program
        {
            static void Main(string[] args)
            {
                ArrayList arr = new ArrayList();
                arr.Add("a");
                arr.Add("b");
                arr.Add("c");
                Console.WriteLine("{0}{1}{2}",arr[0],arr[1],arr[2]);
                Console.Read();
            }
        }
      

  2.   

    除非限定了个数,否则不循环得不到。当然,可以有变相的循环办法:    class Program
        {
            static string s = "";
            static void Main(string[] args)
            {
                ArrayList arr = new ArrayList();
                arr.Add("a");
                arr.Add("b");
                arr.Add("c");
                s = "";
                GetNext(arr, 0);
                Console.Write(s);
            }        static void GetNext(ArrayList a, int Index)
            {
                try {
                s += a[i];
                GetNext(a, i++);
                }
                catch { }
            }
        }或者用GoTo
      

  3.   

      ArrayList arr = new ArrayList();
                arr.Add("a");
                arr.Add("b");
                arr.Add("c");
                string s = string.Join("", arr.ToArray());
      

  4.   

    当然如果你非常清楚的知道,a,b,c相对于ArrayList类首地址的开始地址,还可以用指针来实现,
      

  5.   

      
    class Program
    {
        static string s = "";
        static void Main(string[] args)
        {
            ArrayList arr = new ArrayList();
            arr.Add("a");
            arr.Add("b");
            arr.Add("c");
            s = "";
            GetNext(arr, 0);
            Console.WriteLine(s);
        }
        
        static void GetNext(ArrayList a, int i)
        {
            try {
                s += a[i];
                GetNext(a, i++);
            }
            catch { }
        }
    }
      

  6.   

    晕,修正下:
    class Program
    {
        static string s = "";    static void Main(string[] args)
        {
            ArrayList arr = new ArrayList();
            arr.Add("a");
            arr.Add("b");
            arr.Add("c");
            s = "";
            GetNext(arr, 0);
            Console.WriteLine(s);
        }
        
        static void GetNext(ArrayList a, int i)
        {
            try {
                s += a[i];
                GetNext(a, ++i);
            }
            catch { }
        }
    }
      

  7.   

    我想理论上是可以的,只是C#不支持(我所了解的范围内)
    就相当于sqlserver读取一个表,得到的结果是一行一行的,
    但如果跳过sqlserver直接去硬盘上取数据,就可以为所欲为了
      

  8.   

    去试下吧,我这可以的。            ArrayList arr = new ArrayList();
                arr.Add("a");
                arr.Add("b");
                arr.Add("c");
                string[] str=(string[])arr.ToArray(Type.GetType("System.String"));
                string.Join("", str);
      

  9.   

    RE:string.Join("", str);
    以下是string.join的核心代码string str = FastAllocateString(length);
        fixed (char* chRef = &str.m_firstChar)
        {
            UnSafeCharBuffer buffer = new UnSafeCharBuffer(chRef, length);
            buffer.AppendString(value[startIndex]);
            for (int j = startIndex + 1; j <= num2; j++)
            {
                buffer.AppendString(separator);
                buffer.AppendString(value[j]);
            }
        }
        return str;
      

  10.   

    递归严重影响效率,是没错 现在计算机效能这么好 在大的运算也不是问题
    但最主要是耗费内存资源 来做堆栈 若有100000000个项 真的会影响效率
    实际编程中谁用递归呀。不一定吧
    在实务上常以解决复杂琐碎的问题比如档案结构的解析  我觉得10楼用递归是正解 若在改良一下 ArrayList 不要成为第回参数 可以解决 数据量大的效率问题class Program
    {
        ArrayList m_arr = new ArrayList();
        static void Main(string[] args)
        {
            m_arr.Add("a");
            m_arr.Add("b");
            m_arr.Add("c");
            Console.WriteLine(GetString(m_arr.Count));
        }
        
            private string GetString(int count)
            {
                if (--count > 0)
                    return GetString(count) + m_arr[count].ToString();
                 else
                    return m_arr[0].ToString();
             }
    }
      

  11.   

    递归其实还是循环。
    在汇编里面jmp和call基本等价。jmp就是goto如果我是面试官,我期待的答案是不可能,而不是递归。
      

  12.   

    把ArrayList转化为string数组.
    使用string.Join应该可以.
    没意思,你不循环,总有人要循环.不知道他的意思.