我可以訪問一個名爲Storage的字符串變量。我想將一組字符串與其他變量一起保存到Storage變量中。這可能將一個數組變量保存到一個字符串?如果是我如何從數組中獲取值?請參閱下面的代碼。將字符串數組保存到字符串
// This Storage variable is just for code functionality. I do not create it.
string Storage; // See above^
string Apple = "Red";
string Bannana = "Yellow";
Queue<string> myQ = new Queue<string>();
myQ.Enqueue("zero");
myQ.Enqueue("one");
myQ.Enqueue("two");
myQ.Enqueue("three");
string[] myQ_Array = myQ.ToArray();
Storage = Apple + ";" + Bannana + ";" + myQ_Array[0] + ";" + myQ_Array;
var mySplitStorage = Storage.Split(';');
Console.WriteLine("mySplitStorage[0] = " + mySplitStorage[0]);
Console.WriteLine("mySplitStorage[1] = " + mySplitStorage[1]);
Console.WriteLine("mySplitStorage[2] = " + mySplitStorage[2]);//<--This works
Console.WriteLine("mySplitStorage[3] = " + mySplitStorage[3]);//<--Cant get this to work
Console.Read();
// This is the output
//mySplitStorage[0] = Red
//mySplitStorage[1] = Yellow
//mySplitStorage[2] = zero
//mySplitStorage[3] = System.String[] <--- How do i get the values out of the array?
'VAR第三= mySplitStorage [3];'然後'第三[0]'或'mySplitStorage [3] [0]' –
是否有你創建一個隊列然後將其轉換爲數組的原因,只是爲了不再使用隊列?除非它稍後在代碼中使用,並且您只是不包含該部分,爲什麼不直接創建隊列作爲數組呢? – MattD