TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
onez
NA
73
0
Hashtable arrays
Aug 23 2004 1:37 PM
I'm having a problem using arrays in a hastable. The arrays need to be a fixed size so I assign all of them the same double array with 14 zero values through a foreach statement. I am unable to change the first array in the hashtable without changing all of the other arrays, becuase that same first array they were all assigned with. I describe the problem here through an example. Hashtable H = new Hashtable(); double[] A = {1.5, 2.5, 3.5}; H.Add("A1", A); H.Add("A2", A); double[] T = (double[])H["A1"]; T = StackArrayMix.PopAdd(6.5, T); // this class pops off the last value // and adds a new one like a stack, the A2 value also gets the array, if I would // of given A2 a different array value it would not of happened Console.Write("A1: "); PrintArrayValues(T); // Output: 2.5, 3.5, 6.5 double[] T2 = (double[])H["A2"]; T2 = StackArrayMix.PopAdd(8.88, T2); Console.Write("A2: "); PrintArrayValues(T2); // Output: 3.5, 6.5, 8.88 // Why does the program interconnect the old arrays together and something like // this does not: int x = 5; int y = x; int z = x; y++; // y is now 6 but z stays at 5 Console.WriteLine("x: " + x + "y: " + y + "z: " + z); Maybe there is a better way to do this? Eventually I will need multidimmensional arrays.
Reply
Answers (
1
)
C# opening the file
loop logic problems