title: comparing two lists and removing missing numbers with C#
body: <p>there are two lists:</p>
  
  <pre><code>List&lt;int&gt; list2 = new List&lt;int&gt;(new[] { 1, 2, 3, 5, 6 }); // missing: 0 and 4
  List&lt;int&gt; list1 = new List&lt;int&gt;(new[] { 0, 1, 2, 3, 4, 5, 6 });
  </code></pre>
  
  <p><strong>how do you compare two lists, find missing numbers in List1 and remove these numbers from List1? To be more precise, I need to find a way to specify starting and ending position for comparison.</strong></p>
  
  <p>I imagine that the proccess should be very similar to this:</p>
  
  <p><strong>Step 1.</strong></p>
  
  <pre><code>int start_num = 3; // we know that comparisons starts at number 3
  int start = list2.IndexOf(start_num); // we get index of Number (3)
  int end = start + 2; // get ending position
  int end_num = list2[end]; // get ending number (6)
  </code></pre>
  
  <p>now we've got positions of numbers (and numbers themselves) for comparison in List2 (3,5,6)</p>
  
  <p><strong>Step 2.</strong> To get positions of numbers in List1 for comparison - we can do the following:</p>
  
  <pre><code>int startlist1 = list1.IndexOf(start_num); // starting position
  int endlist1 = list1.IndexOf(end_num); // ending position
  </code></pre>
  
  <p>the range is following: (3,4,5,6)</p>
  
  <p><strong>Step 3. Comparison.</strong> Tricky part starts here and I need a help with it</p>
  
  <p>Basically now we need to compare list2 at (3,5,6) with list1 at (3,4,5,6). The missing number is "4".</p>
  
  <pre><code>// I have troubles with this step but the result will be:
  
  int remove_it = 4; // or int []
  </code></pre>
  
  <p><strong>Step 4. Odd number removal.</strong></p>
  
  <pre><code>int remove_it = 4;
  list1 = list1.Where(a =&gt; a != remove_it).ToList();
  </code></pre>
  
  <p>works great, but what will happen if we have 2 missing numbers? i.e.</p>
  
  <pre><code>int remove_it = 4 // becomes int[] remove_it = {4, 0}
  </code></pre>
  
  <p><strong>Result</strong> As you have guessed the result is new List1, without number 4 in it.</p>
  
  <pre><code>richTextBox1.Text = "" + string.Join(",", list1.ToArray()); // output: 0,1,2,3,5,6
  
  textBox1.Text = "" + start + " " + start_num; // output: 2 3
  textBox3.Text = "" + end + " " + end_num; // output: 4 6
  
  textBox2.Text = "" + startlist1; // output: 3
  textBox4.Text = "" + endlist1; // output: 6
  </code></pre>
  
  <p><strong>Can you guy help me out with Step 3 or point me out to the right direction?</strong></p>
  
  <p>Also, can you say what will happen if starting number(start_num) is the last number, but I need to get next two numbers? In example from above numbers were <strong>3,5,6,</strong> but they should be no different than <strong>5,6,0</strong> or <strong>6,0,1</strong> or <strong>0,1,2</strong>.</p>