c#如何在arraylist中打印字符串的字符

时间:2015-09-19 05:09:30

标签: c# arraylist

此程序打印字符串输入的所有可能性,例如,如果输入为abc',输出应该是组合,这可以工作但是当我创建arraylist时它打印出数字而不是字符串组合,代码:

string input = Console.ReadLine();

int sl = input.Length;
ArrayList arr = new ArrayList();

for (int three = 0; three < sl; three++) {
    for (int two = 0; two < sl; two++) {
        for (int one = 0; one < sl; one++) {
            char onef = input[one];
            char twof = input[two];
            char threef = input[three];


            arr.Add(threef + twof + onef);

            Console.Write(threef);
            Console.Write(twof);
            Console.WriteLine(onef);
        }
    }
}

Console.WriteLine("The elements of the ArrayList are:");
foreach(object obj in arr) {
    Console.WriteLine(obj);
}

arraylist的输出是数字,而不是字符串字符,帮助!

2 个答案:

答案 0 :(得分:2)

只需更改这三行

即可

发件人:

 char onef = input[one];
 char twof = input[two];
 char threef = input[three];

  string onef = input[one].ToString();
  string twof = input[two].ToString();
  string threef = input[three].ToString();

答案 1 :(得分:2)

替代:改变一行:

arr.Add(string.Format("{0}{1}{2}", a, b, c));

char不能像string那样连接在一起。 +以数字解释。