Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am giving a solution in C# but converting it into VB.NET should not be a problem for you. </p> <p>Also I am assuming that the number of objects present in the List(of object) is always 3 and in the order of type int, string, int. </p> <p>The following is my solution to your problem. </p> <ol> <li>Create a new class say "MyList" which inherits from List(of object)</li> <li>Override Equals method in "MyList" class and in that method check if the passed list is same as the current list by checking each element</li> <li>Create the original dictionary as key = "MyList", value = int</li> <li>Create a new dictionary as key = "MyList", value = List(of int)</li> <li>Create a method which will call the overriden equals method and adds a new key/value if returned false and adds the value to that key if returned true</li> </ol> <p>The following is the entire code</p> <pre><code> Dictionary&lt;MyList, List&lt;int&gt;&gt; newOtherDict; private void button1_Click(object sender, EventArgs e) { //Dummy data for testing Dictionary&lt;MyList, int&gt; myDict = new Dictionary&lt;MyList, int&gt;(); myDict.Add(new MyList() {1, "SomeString", 3 }, 1); myDict.Add(new MyList() { 1, "SomeOtherString", 3 }, 12); myDict.Add(new MyList() { 1, "SomeString", 3 }, 123); //This dictionary will contain the consolidated values newOtherDict = new Dictionary&lt;MyList, List&lt;int&gt;&gt;(); for (int i = 0; i &lt; myDict.Count; i++) { AddOrAppendToNewDict(myDict.ElementAt(i)); } } private void AddOrAppendToNewDict(KeyValuePair&lt;MyList, int&gt; keyValue) { var foundPair = newOtherDict.Where(x =&gt; x.Key.Equals(keyValue.Key)); if (foundPair.Count() == 0) { newOtherDict.Add(keyValue.Key, new List&lt;int&gt;() { keyValue.Value }); } else { foundPair.First().Value.Add(keyValue.Value); } } class MyList : List&lt;object&gt; { public override bool Equals(object obj) { List&lt;object&gt; toCompareClass = obj as List&lt;object&gt;; if (Convert.ToInt32(this[0]) == Convert.ToInt32(toCompareClass[0]) &amp;&amp; Convert.ToInt32(this[2]) == Convert.ToInt32(toCompareClass[2]) &amp;&amp; this[1].ToString() == toCompareClass[1].ToString()) return true; return false; } } </code></pre> <p>I hope this solves your problem.</p> <p>Regards,</p> <p>Samar</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload