Loading a .csv file into dictionary, I keep getting the error “cannot convert from 'string[]' to 'string'”

倖福魔咒の 提交于 2019-12-03 12:22:49
Taylor Southwick

If you're using .NET 4.0, the following is really succinct and should accomplish the same thing:

var dict = File.ReadLines("textwords0.csv").Select(line => line.Split(',')).ToDictionary(line => line[0], line => line[1]);

the error is actually because of the ',' you are inputting. It needs an "array" of characters to split from. Here is an example method of splitting using string.split.

string[] parts = line.Split(new string[] { "," }, StringSplitOptions.None);

Hope this helps. this is presuming this is the line the error is coming from as you havn't specified.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!