Set --- hashset <t> and sortedset <t>

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.