I want add every row data from csv into Dictionary in c#
csv is like that :
- id,data
- 1,a
- 2,b
here my code
Dictionary<int, string> m_dicTransactions = new Dictionary<int, string>();
while ((line = sr.ReadLine()) != null)
{
string[] columns = line.Split(',');
m_dicTransactions.Add(columns[0], columns[1]);
}
i want to add id and data to my dictionary, how to do that?
您需要将第一列转换为整数:
m_dicTransactions.Add(int.Parse(columns[0]), columns[1]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.