[英]c# How to print the chars of strings in 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的輸出是數字而不是字符串char,請幫助!
只需更改這三行
從:
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();
備選:更改一行:
arr.Add(string.Format("{0}{1}{2}", a, b, c));
char
不能像string
那樣string
。 +
數字解釋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.