For Loop - Switch refactoring in csv parsing code
<p>I'm making some changes to a bit of our app that parses a csv file. We have a template object that has a set of private fields representing the csv columns and getters and setters for each. This object is only set when parsing the csv file.</p>

<p>The parsing code reads each row of the csv in a string array and splits the array based on ','. Then it parses each column using a for loop - switch structure:</p>

<pre><code>            for (int j = 0; j &lt; sParsedInput.Length; j++)
            {
                sWork = sParsedInput[j];
                switch (j)
                {
                    case 0:
                        Template.column1 = sWork;
                        break;

                    case 1:
                        dteTmpDate = Convert.ToDateTime(sWork);
                        sWork = dteTmpDate.ToString("MM/dd/yyyy");
                        Template.column2 = Convert.ToDateTime(sWork);
                }
            }
</code></pre>

<p>There are about 10 columns, so this goes on for a bit.</p>

<p><strong>Considering I will have to change this function since the input file has been changed dramatically, is there a way to avoid the lengthy switch statement?</strong></p>

<p>I was thinking about moving the parsing code to the properties of the template and relying on the setter to make the conversation from string to dateTime etc. I'm not sure this is a great solution as it might be confusing if someone else decides to use the template object for another purpose. </p>

<p>Thanks</p>
