c# - How should I remove objects from a list when a cancel dialog result is returned? -
i writing c# forms application have many list<t>
lists. have many forms can add , remove objects these lists. if users presses cancel button, , dialog result returned cancel, how best way remove data added lists form?
should take 'snapshot' of lists beforehand, , restore lists, or there better approach?
all lists inherit icustomobject interface, , these lists stored in 1 place. not specific each form, each form can add , edit items in lists.
thanks.
i'd create backup of lists , revert changes if user press cancel.
var list1 = new list<int>() { 1, 2, 3}; var list2 = new list<string>() { "abc", "def", "ghi"}; object[] tempdata = new[] { list1.tolist(), list2.tolist() }; //... user changes in list1, list2 ... list1.add(12); list1.remove(3); list2.remove("def"); if(cancel) { list1 = tempdata[0] list<int>; list2 = tempdata[1] list<string>; }
Comments
Post a Comment