我想從List<string[]>
刪除項目,但刪除屬性不起作用,但如果我使用RemoveAt(0)
(任何int硬編碼的值),那麼它的工作......什麼可以成爲問題。誰能幫我?從列表中刪除項目<string[]>或獲取任何項目的任何位置的索引
這裏是我的代碼...
List<string[]> ipcol1 = new List<string[]>();
ipcol1.Add(new string[] { "test1" });
ipcol1.Add(new string[] { "test2" });
ipcol1.Add(new string[] { "test3" });
ipcol1.Add(new string[] { "test4" });
ipcol1.Remove(new string[] { "test1" });
int i = ipcol1.IndexOf(new string[] { "test4" });
ipcol1.RemoveAt(i);
或者,如果我試圖採取perticular項目的索引,然後它給我(-1)的結果......如果我能得到這個問題的指標那麼我的問題可以解決...請幫助我。
添加到列表中的字符串數組與您在「IndexOf」中使用的字符串數組不同。它們可能具有相同的價值,但它們不是同一個實例。由於數組是*參考*類型,因此您的項目都不會相同。 –