我需要設置一個新的字符串,並且用戶需要設置新的字符串名稱 例如:字符串名稱
int input = 0;
while (input != -1)
{
input = int.Parse(Console.ReadLine());
int count = 0;
count ++;
int ("the " count)= intput;
}
我需要設置一個新的字符串,並且用戶需要設置新的字符串名稱 例如:字符串名稱
int input = 0;
while (input != -1)
{
input = int.Parse(Console.ReadLine());
int count = 0;
count ++;
int ("the " count)= intput;
}
我認爲,就是啥子做YPU需要:
int input = 0;
var inputs = new List<int>();
while (input != -1)
{
input = int.Parse(Console.ReadLine());
int count = 0;
count++;
inputs.Add(input);
}
var result = inputs.Select((j, i) => Tuple.Create("The " + i, j)).ToList();
謝謝你也幫助我很多 –
你不希望有一個 「動態變量」,你想有一個字典。事情是這樣的:
Dictionary<int, int> values = new Dictionary<int, int>();
int count = 0;
int input = 0;
while (input != -1)
{
input = int.Parse(Console.ReadLine());
count++;
values.Add(count, input);
}
如果你需要,但值存儲在這種情況下,似乎是剛剛int
值反正你可以做一些你輸出部分"the"
。如果你想創意,你可以將一些數據類型包裝在自定義類中,並且很容易地從該類中輸出格式化的字符串。
另一個變化要注意上面移動count
外循環的聲明,否則就總是將是1
基本上,幾乎任何時候你發現自己想要一個動態的變量名以下一些模式,你真正想要的是某種集合。也許一個字典,也許一個列表,也許別的東西,等等
謝謝你幫助我很多 –
用戶將不得不永遠輸入值 – Sajeetharan
你是什麼意思? –
我不知道從哪裏開始。計數變量被設置爲0,然後在每次迭代中設置爲1,或者將字符串聲明爲變量名稱,並賦予intput的值。另外,這個應該做什麼呢? –