當前位置:成語大全網 - 新華字典 - 怎樣將字典的key和value值存放到數據庫裏面

怎樣將字典的key和value值存放到數據庫裏面

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 主要功能:顯示所引用