Click here to Skip to main content
15,882,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 .
C#
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");
Posted
Comments
OriginalGriff 16-Feb-14 4:28am    
What's the error?
Any message?
ahmedfcih 16-Feb-14 4:32am    
this is many errors this is my main program http://ideone.com/xlFXLR and this is my class http://ideone.com/rMpHcl code .
OriginalGriff 16-Feb-14 4:38am    
I am not going to unknown websites to pick up unknown content.
If you want help, post it here, not a link.

Help us to help you!
Krunal Rohit 16-Feb-14 4:29am    
and the error is ?
ahmedfcih 16-Feb-14 4:32am    
this is many errors this is my main program http://ideone.com/xlFXLR and this is my class http://ideone.com/rMpHcl code .

If "SomeDATAFile.txt" containing newline separated valid entries that can be parsed into Type double exists on your Desktop, this will work:
C#
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");
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.
 
Share this answer
 
Comments
ahmedfcih 16-Feb-14 6:47am    
thank you for your advice
i use your code but i have some error such that
Error 2 Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<double[],string>' to 'double[]'
BillWoodruff 16-Feb-14 7:17am    
The code in my "solution" is an answer to your original post here where you show the creation of a double[] from reading a .txt file, and then create a Dictionary entry of the form <double[], string>

If you only want to use the double[], just use the variable 'xAry, and don't create the Dictionary.

good luck, Bill
Two problems:
1) In C# an array of doubles is declared as double[] not []double
2) A Dictionary does not have an "add" property. It does have an Add method though:

Try:
C#
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!
 
Share this answer
 
Comments
ahmedfcih 16-Feb-14 4:40am    
i doesn't work
this is my main code http://ideone.com/xlFXLR
and this is my class code http://ideone.com/rMpHcl
please help me
OriginalGriff 16-Feb-14 4:53am    
What part of
"I am not going to unknown websites to pick up unknown content.
If you want help, post it here, not a link."
Did you not read?
ahmedfcih 16-Feb-14 5:03am    
no this is online compiler and this is my code and run with my . without put dictionary i want to make it for list array double [] x and double []y .

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
double[] x = File.ReadAllLines(@"E:\TestFile.txt").Aggregate("", (current, newLine) => current + " " + newLine).Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => double.Parse(s)).ToArray();
double[] y = File.ReadAllLines(@"E:\TestFile2.txt").Aggregate("", (current, newLine) => current + " " + newLine).Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => double.Parse(s)).ToArray();
SimpleDTW dtw = new SimpleDTW(x, y);
dtw.computeDTW();
// double value = dtw.getSum();
double result = new SimpleDTW(x, y).computeFForward();
Console.WriteLine(result);
Console.ReadLine();
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900