Click here to Skip to main content
15,949,686 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to get very continuous random numbers Pin
BoneSoft2-Jul-06 16:39
BoneSoft2-Jul-06 16:39 
GeneralRe: How to get very continuous random numbers Pin
Paul Conrad2-Jul-06 17:19
professionalPaul Conrad2-Jul-06 17:19 
GeneralRe: How to get very continuous random numbers Pin
Judah Gabriel Himango3-Jul-06 5:27
sponsorJudah Gabriel Himango3-Jul-06 5:27 
AnswerRe: How to get very continuous random numbers Pin
Guffa2-Jul-06 11:48
Guffa2-Jul-06 11:48 
AnswerRe: How to get very continuous random numbers Pin
mav.northwind2-Jul-06 23:30
mav.northwind2-Jul-06 23:30 
QuestionMessage Removed Pin
2-Jul-06 4:35
Mandai2-Jul-06 4:35 
AnswerRe: Asking a question Pin
Ravi Bhavnani2-Jul-06 4:55
professionalRavi Bhavnani2-Jul-06 4:55 
QuestionArrays in Hashtables Pin
Mazze.ger1-Jul-06 23:17
Mazze.ger1-Jul-06 23:17 
Hi guys!

A quick question from a c# newbie. Please take a look at the following two examples:

EXAMPLE 1:
using System;
using System.Collections;

class Tester
{
public static void Main()
{
Hashtable x = new Hashtable();
int[] y = { 1, 2, 3 };
x["1"] = y;
int[] z = { 4, 5, 6 };
x["2"] = z;
Console.WriteLine(((int[])x["1"])[1]);
Console.WriteLine(((int[])x["2"])[1]);
System.Threading.Thread.Sleep(25000);
}
}


EXAMPLE 2:
using System;
using System.Collections;

class Tester
{
public static void Main()
{
Hashtable x = new Hashtable();
int[] y = { 1, 2, 3 };
x["1"] = y;
y[0] = 4; y[1] = 5; y[2] = 6;
x["2"] = y;
Console.WriteLine(((int[])x["1"])[1]);
Console.WriteLine(((int[])x["2"])[1]);
System.Threading.Thread.Sleep(25000);
}
}

Example 1 produces the desired output 2 and 5 whereas Example 2 returns 5 and 5.
The only difference being that in Example 1 two variables were used (y and z) to write data to the hashtable whereas Example 2 uses only one variable (y). IMO both cases should produce the very same output, but they obviously don't. Could anyone explain to me why not? I don't understand the logic behind this. Do I always have to use different variables when writing to a hashtable? That would be very inconvinient, especially if the table were to consist of hundreds or even thousands of items!

Any help is greatly appreciated!
Thans for your efforts!!!
Mazze

AnswerRe: Arrays in Hashtables Pin
Guffa1-Jul-06 23:51
Guffa1-Jul-06 23:51 
GeneralRe: Arrays in Hashtables Pin
Mazze.ger2-Jul-06 1:34
Mazze.ger2-Jul-06 1:34 
AnswerRe: Arrays in Hashtables Pin
Guffa2-Jul-06 1:49
Guffa2-Jul-06 1:49 
AnswerRe: Arrays in Hashtables Pin
Nader Elshehabi2-Jul-06 1:56
Nader Elshehabi2-Jul-06 1:56 
GeneralRe: Arrays in Hashtables Pin
Mazze.ger2-Jul-06 2:17
Mazze.ger2-Jul-06 2:17 
Questionhow ot Windows Service Pin
foysal mamun1-Jul-06 21:35
foysal mamun1-Jul-06 21:35 
AnswerRe: how ot Windows Service Pin
Nader Elshehabi2-Jul-06 1:43
Nader Elshehabi2-Jul-06 1:43 
AnswerRe: how ot Windows Service Pin
Ravi Bhavnani2-Jul-06 4:57
professionalRavi Bhavnani2-Jul-06 4:57 
AnswerRe: how ot Windows Service Pin
Paul Conrad2-Jul-06 12:52
professionalPaul Conrad2-Jul-06 12:52 
QuestionCapturing video from webcam using .NET Pin
dmee1-Jul-06 20:33
dmee1-Jul-06 20:33 
AnswerRe: Capturing video from webcam using .NET Pin
Ed.Poore1-Jul-06 23:23
Ed.Poore1-Jul-06 23:23 
NewsRe: Capturing video from webcam using .NET Pin
LongRange.Shooter3-Jul-06 5:26
LongRange.Shooter3-Jul-06 5:26 
QuestionText file parsing Pin
Zeikcied1-Jul-06 19:17
Zeikcied1-Jul-06 19:17 
AnswerRe: Text file parsing Pin
tjvictor1-Jul-06 19:25
tjvictor1-Jul-06 19:25 
NewsRe: Text file parsing Pin
LongRange.Shooter3-Jul-06 5:35
LongRange.Shooter3-Jul-06 5:35 
GeneralRe: Text file parsing Pin
Zeikcied8-Jul-06 18:18
Zeikcied8-Jul-06 18:18 
NewsRe: Text file parsing Pin
LongRange.Shooter9-Jul-06 5:06
LongRange.Shooter9-Jul-06 5:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.