将文本框转换为字典
我正在尝试将文本框条目转换为双精度字典。即
输入文本是:
1,63
2,31
3,78
4,83
然后我用逗号 (,) 分隔该行。
我有下面的代码 - 但 IEnumerable 不起作用。任何帮助将不胜感激!
string input = txtInput.Text;
List<string> list = new List<string>(
input.Split(new string[] { "\r\n" },
StringSplitOptions.RemoveEmptyEntries));
IEnumerable<Dictionary<double, double>> dict = list.Select(row => row.Split(','))
.Select(pair => new Dictionary<string, string>(double.Parse(pair[0]), double.Parse(pair[1])));
I'm trying to convert a textbox entry into a Dictionary of double, double. i.e.
Input text is:
1,63
2,31
3,78
4,83
I'm then splitting the row by a comma (,).
I've got the code below - but the IEnumerable isnt working. Any help would be much appreciated!!
string input = txtInput.Text;
List<string> list = new List<string>(
input.Split(new string[] { "\r\n" },
StringSplitOptions.RemoveEmptyEntries));
IEnumerable<Dictionary<double, double>> dict = list.Select(row => row.Split(','))
.Select(pair => new Dictionary<string, string>(double.Parse(pair[0]), double.Parse(pair[1])));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您可能想要:
但是:
int
或decimal
代替吗?Sounds like you probably want:
However:
double
values for equalty (required by a dictionary) is generally a bad idea. Can you useint
ordecimal
instead?