title: Combine multiple values into one in c#
body: <p>I have a dictionary having ids as key and value will be the ids to which it will be clubbed ( which is actually the ref data).</p>
  
  <p>There is one more list which only contains the ids but for specific name.</p>
  
  <p>First list have 100  different ids from 1 to 100.
  I am checking whether the ids for specific name in list 2 is present in list 1.If they are present then saving those ids. But there is a special condition in it. </p>
  
  <p>e.g. If ids present in list 2 have clubbed ids (which we are checking from the ref dictionary) then we have to save only the clubbed id
  Let us suppose the ids in list 2 is 1,10,21. 1 and 10 are clubbed with 21.Therefore, I only have to save one id which is the clubbed one i.e. 21 but not to save 1 and 10. In this case we are saving only 1 instead of 3.</p>
  
  <p>If these ids dont have any clubbed id then 3 ids will be saved (1,10,21).</p>
  
  <hr>
  
  <p>Updated:</p>
  
  <p>Dictionary have 1 to 100 ids and some of the ids  have clubbed ids and some dont</p>
  
  <pre><code>Dictionary&lt;int,string&gt; dict = new Dictionary&lt;int,string&gt;();
  //Key is id and the value is clubbedid
  dict.Add(1,"21");
  dict.Add(10,"21");
  dict.Add(21,"None"); 
  // etc
  
  //In the list 2 we have ids for specific name 
  List&lt;int&gt; list2 = new List&lt;int&gt;();
  list2.Add(1);
  list2.Add(10);
  list2.Add(21);
  </code></pre>
  
  <p>First i will check whether all the three ids in list 2 are in reference dictionary.And then will assign the value in     other list of object in the field Id.</p>
  
  <pre><code>foreach(int value on list2)
  {
      if(dict.ContainsKey(value))
      {
          List&lt;class&gt; list3 = new  List&lt;class&gt; list3();
          list3.Id = value;
      }
  }
  </code></pre>
  
  <p>So I have added all the three ids 1,10,21 one by one in id field of list3. Now the list3 contains three ids. In the simple     case it is correct where none of the id have clubbed id.</p>
  
  <p>But as you can see in my reference dictionary, ids 1 and 10 have clubbed id as 21.Therefore, in the list3 I have to store     only one value which is 21 (only clubbed id removing the other one 1 and 10)</p>
  
  <p>Any help.</p>