2014-07-24 283 views
0

在vb.net中在以下代碼中使用Items.Remove和Items.RemoveAt有什麼區別?從VB中刪除項目

If lstCountries.SelectedIndex <> -1 Then 
     lstCountries.Items.RemoveAt(lstCountries.SelectedIndex) 
    End If 
+0

http://stackoverflow.com/questions/3211679/is-it-faster-the-listt-removet-or-listt-removeatint-method – HengChin

+3

當你把鼠標放在單詞上時,你的VS是否告訴你它的區別?由Intellisense提供?不是你的VS有對象瀏覽器(查看菜單 - >對象瀏覽器)給你任何你想要的定義? – Plutonix

回答

2

的「RemoveAt移除」通過指數至極除去identifys單個對象但使用的「刪除」,可以刪除任何對象simlar在參數至極給出的一個裝置,如果存在具有相同propreyties一個確切的對象它也可以刪除

0

removeAt以index作爲參數,同時刪除take item作爲參數。 RemoveAt更快,因爲它直接處理索引並執行操作,同時刪除檢查所有索引以查找匹配的項目。