数组中有四个字符,a b c d怎么将他们倒置,变成dcba啊

解决方案 »

  1.   

    string[] s = { "a", "b", "c", "d" };
    List<string> list = new List<string>();
    for (int i = s.GetLength(0) - 1; i >= 0; i--)
    {
        list.Add(s[i]);
    }
    s = list.ToArray();
      

  2.   

    用linq写:s = s.Reverse().ToArray();
      

  3.   


       string[] str = { "a", "b", "c", "d" };
                string[] str2 = new string[4];
                for (int i = 0; i < str.Length; i++)
                {
                    str2[i] = str[(str.Length - 1) - i];
                    Console.WriteLine("{0}", str2[i]);
                }            //string[] name = { "a", "b", "c", "d" };
                //for (int i = 0; i < name.Length / 2; i++)
                //{
                //    string temp = name[i];
                //    name[i] = name[name.Length - 1 - i];
                //    name[name.Length - 1 - i] = temp;
                //}
                //for (int i = 0; i < name.Length; i++)
                //{
                //    Console.WriteLine(name[i]);
                //}
      

  4.   


                string txt = "abcda";
                string rslt = string.Join("", txt.Reverse()).ToString();
                Console.Write(rslt);
      

  5.   


    string[] txt = { "a","b","c","d","a"};
    string rslt = string.Join("", txt.Reverse());
    Console.Write(rslt);
      

  6.   

    LINQ            string[] txt = { "a", "b", "c", "d", "a" };
                txt = txt.Reverse().ToArray();
      

  7.   

    数组名.Reverse()  //将数组里的元素倒序
      

  8.   

    char[] a = { 'a', 'b', 'c', 'd','e' };
                char b;
                int len = a.Length;
                for (int i = 0; i < len / 2; i++)
                {
                    b = a[i];
                    a[i] = a[len - i - 1];
                    a[len - i - 1] = b;
                }