本文实例为大家分享了一个读写csv文件的c#类,供大家参考,具体内容如下
using system; using system.collections.generic; using system.io; using system.text; namespace csvdemo { /// <summary> /// csvutil is a helper class handling csv files. /// </summary> public class csvutil { private csvutil() { } //write a new file, existed file will be overwritten public static void writecsv(string filepathname,list<string[]>ls) { writecsv(filepathname,false,ls); } //write a file, existed file will be overwritten if append = false public static void writecsv(string filepathname,bool append, list<string[]> ls) { streamwriter filewriter=new streamwriter(filepathname,append,encoding.default); foreach(string[] strarr in ls) { filewriter.writeline(string.join (“,",strarr) ); } filewriter.flush(); filewriter.close(); } public static list<string[]> readcsv(string filepathname) { list<string[]> ls = new list<string[]>(); streamreader filereader=new streamreader(filepathname); string strline=""; while (strline != null) { strline = filereader.readline(); if (strline != null && strline.length>0) { ls.add(strline.split(',')); //debug.writeline(strline); } } filereader.close(); return ls; } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论