title: coma separated string to List object
body: <p>I have a function that is using two for loops.  This needs to run 100k times once for every row in a particular table.  The data comes in in a string comma separated values. I need to turn this data into a Bag Object.  I have a working solution below However, I was wondering if there is a faster approach to this problem.</p>
  <p>Data comes in like this.</p>
  <pre><code>string bagList=&quot;2C28DB,737,2C28DB,738,2C28DB,739,2C28DB,740,2C28DB,741,2C28DB,742,2C28DB,743,2C28DB,744,2C28DB,745,2C28DB,746,2C28DB,747,2C28DB,748,2C28DB,749,2C28DB,750,2C28DB,751,2C28DB,752,2C28DB,753,2C28DB,754,2C28DB,755,2C28DB,756,&quot;
  </code></pre>
  <p>The BagModel looks like this</p>
  <pre><code>  public class BagsModels
     {
      public string LotNumber { get; set; }
      public string BagNumber { get; set; }
     }
  </code></pre>
  <p>I use a split to get an array then load the odds in one list and evens in another list.  From here  I create a bag model object and load both lists into this and add it to the final list.  I use the if statement not sure if the last comma will create an empty value in the array.  The string always contains pairs.  There will never be a case where it does not have a lot number and bag number together.  Any help would be appreciated.</p>
  <pre><code>internal static IEnumerable&lt;BagsModels&gt; ListifyTheString(string bagList)
      {
          List&lt;BagsModels&gt; temp = new();
          string[] temp2 = bagList.Split(',');
          List&lt;string&gt; lotno = new();
          List&lt;string&gt; bagno = new();
          for(int i = 0; i &lt; temp2.Length; i++)
          {
              if(temp2[i] != &quot;&quot;)
              {
                  if(i%2 == 0)
                  {
                      lotno.Add(temp2[i]);
                  }
                  else
                  {
                      bagno.Add(temp2[i]);
                  }
              }
          }
          for(int j = 0; j &lt; lotno.Count; j++)
          {
              BagsModels temp3 = new();
              temp3.LotNumber = lotno[j];
              temp3.BagNumber = bagno[j];
              temp.Add(temp3);
          }
          return temp;
      }
  </code></pre>