-2
如何在列表中移除一個實體,並添加另一個實體同一個列表在C#如何刪除一個實體的名單,並在C#中添加其他實體同一列表
如何在列表中移除一個實體,並添加另一個實體同一個列表在C#如何刪除一個實體的名單,並在C#中添加其他實體同一列表
假設您有一個名爲listBox1的列表框。如果您想從中刪除所選項目,請使用Items.Remove()方法,並將SelectedItem屬性作爲參數傳遞。 用於添加實體Items.Add()並將其作爲要插入的值傳遞。
var yourList = new Collection<EntityType>();
yourList.Remove(entity);
yourList.Add(otherEntity);
或更換:
yourList[yourList.IndexOf(entity)] = otherEntity;
您是否在原始 – 2009-12-23 11:55:55
的索引處添加新的實體僅限特定位置 – ratty 2009-12-23 11:59:24