tag: set C # Set observablecollection
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; using system. collections. objectmodel; namespace consoleapplication2 {class program {static void main (string [] ARGs) {// observed collection observablecollection <string> OC = new observablecollection <string> (); oC. collectionchanged + = oc_collectionchanged; oC. add ("A"); oC. add ("B"); oC. insert (2, "C"); oC. R Emove ("C"); foreach (VAR item in OC) {console. writeline (item);} console. readkey (); // output: // operation: Add // Added Index: 0 // operation: Add // Added Index: 1 // operation: add // Added Index: 2 // operation: Remove // Added Index: 2 // A // B} Private Static void oc_collectionchanged (Object sender, system. collections. specialized. notifycollectionchangedeventargs e) {console. writeline ("Operation: {0}", E. action. tostring (); // the operation that causes the event if (E. newitems! = NULL) // Add {console. writeline ("added index: {0}", E. newstartingindex. tostring ();} If (E. olditems! = NULL) // Delete {console. writeline ("deleted index: {0}", E. oldstartingindex. tostring ());}}}}
Observability set --- observablecollection <t>