hi..i am using hashset to to my intersection.But still cannot intersect the two hashset successfully.I need some help from you guys..
Now,
my first hashset include the number in string
2
1
3
4
5
my second hashset include the number in string (in line)
1 2
1 2 3
2 3
2 3 4
..........(many lines)

how to intersect this two hashset?

HashSet<string>hs1 = new HashSet<string>();

           var g = from k in sItem.Keys
                   orderby sItem[k] descending
                   select k;
          
           foreach (var k in g)
           {
               //display3 += k + ":" + sItem[k] + "\r\n";
               SingleSupport.AppendText(k + ":" + sItem[k] + "\r\n");
               hs1.Add(k.ToString());
               
           }
          
           HashSet<string> hs2 = new HashSet<string>();
           //key and values for comabination
           IDictionaryEnumerator et = itemS.GetEnumerator();
           while (et.MoveNext())
           {
               KeyitemS.AppendText(et.Key.ToString() + ":" + et.Value.ToString()+"\r\n");
               // MessageBox.Show(et.Key.ToString() + ":" + et.Value.ToString() + "\r\n");
               hs2.Add(et.Key.ToString());
           }

here is my coding.Hope someone can help me....thank you.

Recommended Answers

All 8 Replies

Nothing in the first set matches anything in the second set so the intersection is empty.

How i turn the second hashset to vertical and intersect with the firstset one line by one line..This is the problem what i face now...

Now, i do can got improvement already but still face a bit problems. My hashset, hs1 is store the data
2
1
3
4
5
my second data i store by using arraylist
1 2
1 2 3
1 2 3 4
1 2 4
1 3
1 3 4
1 4
2 3
2 3 4
2 4
2 5
3 4
then i store to hashset, hs2 after i split the data.
Now i do the intersection between hs1 and hs2.
but my output just show the first output only that is 2 1 and keep looping 12 times..
How i fix this problem ...someone can help me...?
here is my code

HashSet<string>hs1 = new HashSet<string>();

           var g = from k in sItem.Keys
                   orderby sItem[k] descending
                   select k;
          
           foreach (var k in g)
           {
               //display3 += k + ":" + sItem[k] + "\r\n";
               SingleSupport.AppendText(k + ":" + sItem[k] + "\r\n");
               hs1.Add(k.ToString());     
           }
      
         
           ArrayList myArray = new ArrayList();
           //key and values for comabination
           IDictionaryEnumerator et = itemS.GetEnumerator();
           while (et.MoveNext())
           {
               KeyitemS.AppendText(et.Key.ToString() + ":" + et.Value.ToString() + "\r\n");
               myArray.Add(et.Key.ToString());
           }  
  
           HashSet<string> hs2 = new HashSet<string>();
           for (int i = 0; i < myArray.Count; i++)
           {
                foreach (string h in myArray[i].ToString().Split(' '))
               {
                  // MessageBox.Show(h);
                   hs2.Add(h);
               }
                for (int w = 0; w < hs2.Count; w++)
                {
                    hs1.IntersectWith(hs2);
                }
                   
               foreach (string j in hs1)
                {
                     MessageBox.Show(j);
                }
            }

Line 27: Could you elaborate on the fact that you are using the ToString() method on an array that already contains strings?

because i need to split it to single item...

Duno if it will help but try and remove lines 32,33 and 35.

Still cannot....no output come out...

i realize that my hs2 store data not correctly ...someone can help me to solve this problem..???

HashSet<string> hs2 = new HashSet<string>();
           for (int i = 0; i < myArray.Count; i++)
           {
                foreach (string h in myArray[i].ToString().Split(' '))
               {
                  // MessageBox.Show(h);
                   hs2.Add(h);
               }
                for (int w = 0; w < hs2.Count; w++)
                {
                    hs1.IntersectWith(hs2);
                }
 
               foreach (string j in hs1)
                {
                     MessageBox.Show(j);
                }
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.