A
aperrien
Hello all,
I'm learning C# from a C/C++ background, and I came across an odd
problem.
I have a hashtable that holds a string and a struct like so:
private Hashtable MyTable = new Hashtable();
public class MyData
{
public long int x,y,number;
public Tile( long int xx, long int yy, long int num )
{
x = xx;
y = yy;
number = num;
}
}
MyData DataPoint;
MyData.Add[SomeString,DataPoint];
----- More code ----
foreach(DictionaryEntry DataPoint in MyTable)
{
MyData D = (MyData)DataPoint.Value;
D.x = 10;
}
When I try to access the members of D, I get errors. Why?
Can't I use a hashtable to store struct or class elements like a C++
map?
I'm learning C# from a C/C++ background, and I came across an odd
problem.
I have a hashtable that holds a string and a struct like so:
private Hashtable MyTable = new Hashtable();
public class MyData
{
public long int x,y,number;
public Tile( long int xx, long int yy, long int num )
{
x = xx;
y = yy;
number = num;
}
}
MyData DataPoint;
MyData.Add[SomeString,DataPoint];
----- More code ----
foreach(DictionaryEntry DataPoint in MyTable)
{
MyData D = (MyData)DataPoint.Value;
D.x = 10;
}
When I try to access the members of D, I get errors. Why?
Can't I use a hashtable to store struct or class elements like a C++
map?