2013-10-19 78 views
0

我試圖通過使用索引號的整數得到一個字符串數組中的元素,但我不斷收到一個錯誤:數組索引與整數

Cannot apply indexing with [] to an expression of type 'int'

我會非常感激可作爲任何幫助我對於嚴肅的編程頗爲陌生。

下面的代碼:http://pastebin.com/sa91zHWw

assetClient.DownloadFile("https://s3-eu-west.amazonaws.com/delvegame/versions/" +versionList[numOfItems]+".txt"); 
+3

我們展示versionList的定義是什麼? –

+0

它看起來像'versionList'是一個'int',而不是一個數組。 – Lee

+1

發佈'versionList'的方式 –

回答

-1

試試這個:

for (int i = 0; i < numOfItems; i++) 
{ 
    if (versionDropdown.SelectedIndex == i) 
    { 
     assetClient.DownloadFile("https://s3-eu-west.amazonaws.com/delvegame/versions/" +versionList[i].ToString()+".txt") 
    } 
} 
+0

好的,謝謝。我最初將versionList定義爲字符串數組: –

+0

'String [] versionList = File.ReadAllLines(runpath +「\\ cfg \\ versionList.txt」);' –

0

我想你已經聲明versionList作爲

private int versionList; 

當你想讓它是一個數組。您應該將定義修改爲

private int[] versionList; 
0

這真的好像versionList變量是int型的,而不是一個string陣列像你描述。

這就解釋了爲什麼你得到這個消息:

Cannot apply indexing with [] to an expression of type 'int'

改變其聲明:

private int[] versionList; 

或:

private string[] versionList;