Write list to csv file c# -


imagine have 2 lists filled values. want elements first list, written first column, elements second list written second column , on.

if both list have same size, works fine:

 (int = 0; < valuearray.count(); i++)  {       var newline = string.format("{0},{1}", valuearray.elementat(i), secondvaluearray.elementat(i));       sw.write(newline);  } 

my problem if lists have different sizes, code fails out of range exception obviously. tried adding ',' between columns it's not working.

instead of elementat should use elementatordefault :

according msdn

returns element @ specified index in sequence or default value if index out of range.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -