Hashset <t> unordered list with no duplicates
Sortedset <t> non-repeated ordered list
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; namespace consoleapplication8 {class program {static void main (string [] ARGs) {// ============================ [hashset <t>] = ========================= // ------------------- Add a hashset <string> test = new hashset <string> {"", "B", "C"}; If (! Test. add ("A") // if the list exists, it is not added and false console is returned. writeline ("This element already exists, do not add"); If (test. add ("D") console. writeline ("successfully added element"); // ----------------- compare hashset <string> test1 = new hashset <string> {"A", "B", "C "}; hashset <string> Test2 = new hashset <string> {"A", "B", "C", "D"}; If (test1.issubsetof (Test2) {console. writeline ("each element of test1 has Test2");} If (test1.issubsetof (Test2) {console. writeline ("Test2 has additional elements relative to test1");} If (test1.overlaps (Test2) {console. writeline ("Test2 and test1 have a common element ");} // ===============================[ hashset <t>] ==== ================================= // ------------ Add a set sortedset <string> SD = new sortedset <string> (test1 ); // Add all elements in test1 to the ordered list SD. unionwith (Test2); // Add all elements in Test2 to the ordered list. [duplicate elements are excluded from the result and sorted.] SD. add ("AA"); // ------------ delete a set SD. remove ("D"); // Delete the Matching Element SD. removewhere (r => r = "AA"); // Delete the Matching Element SD. inclutwith (test1); // Delete the set foreach (VAR item in SD) {console. writeline (item);} console. readkey ();}}}
This article from the "programmer's home" blog, please be sure to keep this source http://962410314.blog.51cto.com/7563109/1548502
Set --- hashset <t> and sortedset <t>