I have 2 sortedList. The 2 sortedList code are shown below. May i know how to compare these 2 sortedList?

 public void Display()
        {

            foreach (String sort in lbCombinations.Items)
            {


                if (!(sortList.ContainsKey(sort)))
                {
                    sortList.Add(sort, 1);
                }
                else
                {
                    int Count = (int)sortList[sort];
                    sortList[sort] = Count + 1;
                }

            }

            IDictionaryEnumerator enumerator = sortList.GetEnumerator();
            richTextBox1.Clear();
            while (enumerator.MoveNext())
            {
                richTextBox1.AppendText("(" + enumerator.Key.ToString() + "): " + " " + enumerator.Value.ToString() + "\n");

            }
        }
        public void Display1()
        {
            richTextBox2.Clear();
            foreach (String sort1 in txtCaseInputs.Lines)
            {

                if (!(sortList1.ContainsKey(sort1)))
                {
                    sortList1.Add(sort1, 1);
                }
                else
                {
                    int Count = (int)sortList1[sort1];
                    sortList1[sort1] = Count + 1;
                }

            }


            IDictionaryEnumerator enumerator1 = sortList1.GetEnumerator();

            while (enumerator1.MoveNext())
            {

                richTextBox2.AppendText("(" + enumerator1.Key.ToString() + "): " + " " + enumerator1.Value.ToString() + "\n");
            }
        }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

And what would you like to know? Only if they are equal?
Or to the the same values back (or to get the vlaues which are not in both array)?

Mitja

This is an example of mine, how do you compare two lists:

//SORTED LISTS:
            SortedList<int, int> sList1 = new SortedList<int, int>();
            for (int i = 0; i < 10; i++)
                sList1.Add(i, i);
            SortedList<int, int> sList2 = new SortedList<int, int>();
            for (int i = 0; i < 5; i++)
                sList2.Add(i * 2, i * 2);

             bool bDiff = sList1.SequenceEqual(sList2);  //boolean value (true, false), if they are equal
            var listDiff = sList1.Except(sList2);        //an actual new list, with the difference in both lists
            foreach (var item in listDiff)
                Console.WriteLine(item);

            Console.ReadLine();

Based on my previous code you can do:

//Get the keys which are not in both lists:
var bKeysDiff = sList1.Except(sList2).Select(s => s.Key).ToArray();
foreach (var key in keysDiff) Console.WriteLine(key);

now i have another problem. hope anyone can help me.
the keys in my sortedlist1 are : (1)
(2)
(1 2)
(3)
the keys in my sortedlist2 are: (1)
(2)
(3)
now i wan compare every keys in sortedlist1 with sortedlist2.
if any key in sortedlist1 which is same in sortedlist2 ,then it wont come out any output. the exactly output that i want is like shown below: (1):(2)
(1):(3)
(2):(1)
(2):(3)
(1 2):(3)

the answer is like this--> (1): (2)
(1): (3)
(2): (1)
(2): (3)
(1 2) : (3)

This article has been dead for over six months. Start a new discussion instead.