列表数组的字典 [英] Dictionary for list array
问题描述
我想为数组列表制作字典我读取他的文本文件元素为双数组
这是我的代码,但我有错误,无法解决它。请帮忙 。
I want to make dictionary for array list i read his element for text file as array of double
this is my code but i have error and can't solve it. help please .
Dictionary<[]double , string> x = new Dictionary<[]double , string>();
Dictionary<[]double , string> y = new Dictionary<[]double , string>();
x.add= (File.ReadAllLines(@"E:\TestFile.txt").Aggregate("", (current, newLine) => current + " " + newLine).Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => double.Parse(s)).ToArray(),"x array");
y.add = (File.ReadAllLines(@"E:\TestFile2.txt").Aggregate("", (current, newLine) => current + " " + newLine).Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => double.Parse(s)).ToArray(),"y array");
推荐答案
两个问题:
1)在C#中,一个双精度数组被声明为double []
不是[] double
2)字典没有添加属性。它确实有添加
方法:
尝试:
Two problems:
1) In C# an array of doubles is declared asdouble[]
not[]double
2) A Dictionary does not have an "add" property. It does have anAdd
method though:
Try:
Dictionary<double[] , string> x = new Dictionary<double[] , string>();
Dictionary<double[] , string> y = new Dictionary<double[] , string>();
x.Add(File.ReadAllLines(@"E:\TestFile.txt").Aggregate("", (current, newLine) => current + " " + newLine).Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => double.Parse(s)).ToArray(),"x array");
y.Add(File.ReadAllLines(@"E:\TestFile2.txt").Aggregate("", (current, newLine) => current + " " + newLine).Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => double.Parse(s)).ToArray(),"y array");
但是我不知道它是否会起作用......但它应该编译!
But I have no idea if it will work...but it should compile!
如果SomeDATAFile.txt包含新行分隔的有效条目可以解析为您的桌面上存在类型double,这将工作:
If "SomeDATAFile.txt" containing newline separated valid entries that can be parsed into Type double exists on your Desktop, this will work:
private string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Dictionary<double[] , string> x = new Dictionary<double[] , string>();
double[] xAry = File.ReadAllText(path + @"\SomeDATAFile.txt")
.Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
.Select(s => double.Parse(s)).ToArray();
x.Add(xAry,"x array");
我想建议您可以更好地回答这样的问题(在StackOverFlow以及此处询问)如果您:
1 。给出你正在使用的源代码的链接:对于DTW类:[ ^ ]
2.在CodeProject上,使用编辑器格式化代码,就像在StackOverFlow上一样。
3.清楚地描述所有错误信息。
4.回答直接问你的问题:不要重新发布代码。
您可能知道,Visual Studio Express是免费的;如果您可以离线编译,我认为您的工作效率会提高。
I'd like to suggest that you can get better responses to questions like this (asked on StackOverFlow as well as here) if you:
1. give links to the source code you are using: for the DTW Class: [^]
2. On CodeProject, use the editor to format your code like you did on StackOverFlow.
3. clearly describe all error messages.
4. respond to questions asked you directly: do not repost code.
As you may know, Visual Studio Express is free; I think your productivity will improve if you can compile off-line.
这篇关于列表数组的字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!