C # determines that a set is a subset of another set,

Source: Internet
Author: User

C # determines that a set is a subset of another set,

There are two sets:

 

String [] bigArr = new string [] {"a", "B", "c "};
String [] smallArr = new string [] {"a", "B "};

 

Now we need to determine whether smallArr is a subset of bigArr. If bigArray and smallArr are used to compare and evaluate the difference set, if the number of difference sets is greater than 0, smallArr is a subset of bigArr.

 

// Based on the large set, obtain the var variance Tarr = bigArr of the big set based on the small set. t (smallArr); // judge whether it is a subset if (exceptArr. any () {Console. writeLine ("samllArr is a subset of bigArr");} else {Console. writeLine ("samllArr is not a subset of bigArr ");}

 

In the preceding method, you can only determine whether it is a subset, that is, the set element of the subset is always smaller than the large one.

 

Sometimes, there is a need to determine whether bigArr contains smallArr, that is, smallArr can be a subset of bigArr, or it can be the same as bigArr.

 

// Determine whether it is a subset or two sets are the same if (smallArr. all (t => bigArr. any (B => B = t) {Console. writeLine ("samllArr is a subset or the same as bigArr");} else {Console. writeLine ("samllArr is not a subset or the same as bigArr ");}

 

Related Article

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.