文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>泛型在CVS数据读取中的应用

泛型在CVS数据读取中的应用

时间:2010-12-11  来源:hfliyi

 

代码
public List<Dictionary<string, string>> GetData(string filePath, out List<string> Column)
{
Column
= new List<string>();
List
<Dictionary<string, string>> Data = new List<Dictionary<string, string>>();
string strLine = "";
string[] strArray;
StreamReader sr
= new StreamReader(filePath);
strLine
= sr.ReadLine();
if (strLine == null || strLine == "")
{
return new List<Dictionary<string, string>>();
}
strArray
= strLine.Split(',');
foreach (string item in strArray)
{
Column.Add(item);
}
strLine
= sr.ReadLine();
while (strLine != null)
{
strArray
= strLine.Split(',');
Dictionary
<string, string> dict = new Dictionary<string, string>();
for (int i = 0; i < Column.Count; i++)
{
dict.Add(Column[i], strArray[i]);
}
Data.Add(dict);
strLine
= sr.ReadLine();
}
sr.Close();
return Data;
}

 

调用方法如下:

  List<string> Column;
            List<Dictionary<string, string>> Date = GetData(this.textBox1.Text.Trim(), out Column);
            string str = "";
            foreach (Dictionary<string, string> item in Date)
            {
                foreach (string item1 in Column)
                {
                    str += item[item1] + "   ";
                }
                str += Environment.NewLine;
                   
            }
            this.textBox2.Text = str;

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载