怎样将字典的key和value值存放到数据库里面
1个回答
展开全部
public Dictionary Read(string path) //读txt文件 返回字典
{
StreamReader sr = new StreamReader(path,Encoding.Default);
String line;
var dic = new Dictionary();
while ((line = sr.ReadLine()) != null)
{
var li= line.ToString().Splite(","); //将一行用,分开成键值对
dic.Add(li.key,li.value);
}
return dic;
}
public void Write(string path,Dictionary mydic) //将字典写入txt
{
FileStream fs = new FileStream(path, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
//开始写入
foreach(var d in mydic)
{
sw.Write(d.key.+","+d.value); //键值对写入,用逗号隔开
}
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
}
名称:COLUMN 主要功能:显示所引用
{
StreamReader sr = new StreamReader(path,Encoding.Default);
String line;
var dic = new Dictionary();
while ((line = sr.ReadLine()) != null)
{
var li= line.ToString().Splite(","); //将一行用,分开成键值对
dic.Add(li.key,li.value);
}
return dic;
}
public void Write(string path,Dictionary mydic) //将字典写入txt
{
FileStream fs = new FileStream(path, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
//开始写入
foreach(var d in mydic)
{
sw.Write(d.key.+","+d.value); //键值对写入,用逗号隔开
}
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
}
名称:COLUMN 主要功能:显示所引用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询