 ## 2 replies

Last post Aug 10, 2011 10:34 PM by Decker Dong - MSFT

• ### how to find out two sets are disjoint sets

Hi friends,

i am facing a problem related to sets. Here is my problem...

i will get the limits of three sets.. like SetA=[1,5] and SetB=[6,7] and SetC=[8,15], these numbers are limits of the sets,not the actual elemets... which means SetA will have elements from 1 to 5 and setB will have 6 to 7 and SetC will have elements from 8 to 15..

i want to know whether these sets are disjoint sets or not?

Thank you...

Click on "Mark as Answer" button if this post is useful.

My blog: PashamBlog
• ### Re: how to find out two sets are disjoint sets

```var Sets = new [] {new {name = "SetA", min = 1, max = 5},
new {name = "SetB", min = 6, max = 7},
new {name = "SetC", min = 8, max = 15}};

bool Overlaps = (from s1 in Sets
from s2 in Sets
where s1.name != s2.name && s1.min <= s2.max && s1.max >= s2.min
select new {s1,s2}).Any();```
• ### Re: how to find out two sets are disjoint sets

Aug 10, 2011 10:34 PM|Decker Dong - MSFT|LINK

Hello：）

Another way——Mr.Techno——You can use the extended method of "Intersect" to check whether they have the common things...

``` int[] set1 = {1,2,3,4,5 };
int[] set2 = {6,7,8,9,10 };
int[] set3 = {4,5,6,7,8};

//more than one means the intersect array

var result1 = set1.Intersect(set2).Count()>0;

var result2 = set1.Intersect(set3).Count()>0;```