title: Split List of objects based on object type
body: <p>I have list of objects as below - "Text1", "Text2", new UndefinedInfo("Undfined1"), new UndefinedInfo("Undfined2"), new UndefinedInfo("Undefined3"), "Text3"</p>
  
  <p>I need output as below:</p>
  
  <p>Output 
  // List> 
  0 – Text1, Text2
  1 – Undefined1, Undefined2, Undefined3
  2 – Text3</p>
  
  <p>I managed to write below function which is bad but somehow working fine. Is there any way to achieve the same using LINQ extensions - TakeWhile or SkipWhile or using yield. Any help highly appreciated:</p>
  
  <pre><code>public static List&lt;List&lt;object&gt;&gt; PartitionByTypes(List&lt;object&gt; values)
  {
  List&lt;List&lt;object&gt;&gt; partitionedList = new List&lt;List&lt;object&gt;&gt;();
  
          int j;
          for (int i = 0; i &lt; values.Count; i++)
          {
              j = i;
              List&lt;object&gt; subList = new List&lt;object&gt;();
              Type t = values[j].GetType();
              do
              {
                  subList.Add(values[j]);
                  j++;
                  if (j == values.Count)
                  {
                      break;
                  }
              } while (values[j].GetType() == t);
              partitionedList.Add(subList);
              i = j - 1;
          }
  
          return partitionedList;
      }
  </code></pre>