title: inserting element into a list, if condition is met with C#
body: <p><strong>How to insert some number into the middle of the list, if there is no such number present?</strong></p>
  
  <p>In the example below I'm trying to insert number 4</p>
  
  <pre><code>        List&lt;int&gt; list1 = new List&lt;int&gt;(){ 0, 1, 2, 3, 5, 6 };
          int must_enter = 4;
          if (!list1.Contains(must_enter))
          {
              list1.Add(must_enter);
          }
  </code></pre>
  
  <p>As the result number will be entered at the end of the list, but I want it <strong>right after 3 (before 5)</strong>.</p>
  
  <p>please note that due to project's specifics I can't use sorted list, but all numbers in the list are <strong>guaranteed</strong> to be in ascending order (0,2,6,9,10,...)</p>
  
  <p><strong>EDIT:</strong> I knew about an error and that's what I did:</p>
  
  <pre><code>        List&lt;int&gt; list0 = new List&lt;int&gt;() { 1, 2, 3, 5, 6 };
          int must_enter = 7;
          if (!list0.Contains(must_enter))
          {
              if (must_enter &lt; list0.Max())
              {
                  int result = list0.FindIndex(item =&gt; item &gt; must_enter || must_enter &gt; list0.Max());
                  list0.Insert(result, must_enter);
              }
              else
              {
                  list0.Add(must_enter);
              }
  
          }
  </code></pre>
  
  <p>edit2: anyway I've switched to BinarySearch method due to several factors. Everyone thanks for your help!</p>