C # HashSet (temporary notes, no references, please be cautious)

Source: Internet
Author: User

HashSet is a collection, similar to a dataset, but its main purpose is to store elements of the same type (string, Row, table, and so on), and if the added element is inconsistent with the initial type defined, it will fail to compile directly.

For example:

Hashset<string> hs=new hashset<string>;

BOOL Result1=hs.add ("AA");//Returns True

BOOL Result2=hs.add ("BB");//Returns True

BOOL Result3=hs.add (33);//Direct grammar does not pass

Another example:

DataRow dr=new DataRow ();

Hashset<datarow > Hs=new hashset<datarow >;

BOOL Result1=hs.add ("AA");//Direct grammar does not pass

BOOL Result2=hs.add (DR);//Returns True

If we want to determine whether the elements inside the hashset are duplicated, the direct hs.count (), if greater than 1, indicates there is duplicate data, otherwise there is no repetition. In addition, we can use HS. Unionwith the data merge for distinct.

C # HashSet (temporary notes, no references, please be cautious)

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.