How to skip first line while reading csv using streamreader

后端 未结 5 1121
自闭症患者
自闭症患者 2020-12-14 01:21

I have my following code to read values from csv file and do some processing. I would like to skip the first row of the input csv file as it contains header text but I\'d wa

5条回答
  •  孤街浪徒
    2020-12-14 01:50

    I recommend, to use technique to handle such situation,

                    int row = 0;
                    using (StreamReader sr = new StreamReader(filePath))
    
                    {
                       While(reader.Read()) //Each row of the file
                        {
                            row++;
                            if(row==1)
                            {
                                continue;
                            }
                   }
    ... code..
    }
    

提交回复
热议问题