B
Brian
I'll provide a working example if this isn't some cluelessness on
my part (i.e. someone can spot the issue right away). Can someone
tell me why a cast isn't working below as an index?
Fields is a simple enum.
enum fields {field1,field2,field3};
mydata is an array of MyAbstractDataType. Actual elements of the
array are instances of a derived class.
When I define a integer and assign it f casted to an integer, it
works as an array index with no problems. (first line) If I cast
f to an integer and use that as an array index, it always has a
value of zero.
I'm really puzzled. Thanks.
public Hashtable Data
{
get
{
int x;
Hashtable data = new Hashtable();
foreach (Fields f in Enum.GetValues(typeof(Fields)))
{
x = (int)f;
data.Add(f,mydata[x]); // works
data.Add(f,mydata[((int)f)]); // doesn't work
}
return data;
}
}
my part (i.e. someone can spot the issue right away). Can someone
tell me why a cast isn't working below as an index?
Fields is a simple enum.
enum fields {field1,field2,field3};
mydata is an array of MyAbstractDataType. Actual elements of the
array are instances of a derived class.
When I define a integer and assign it f casted to an integer, it
works as an array index with no problems. (first line) If I cast
f to an integer and use that as an array index, it always has a
value of zero.
I'm really puzzled. Thanks.
public Hashtable Data
{
get
{
int x;
Hashtable data = new Hashtable();
foreach (Fields f in Enum.GetValues(typeof(Fields)))
{
x = (int)f;
data.Add(f,mydata[x]); // works
data.Add(f,mydata[((int)f)]); // doesn't work
}
return data;
}
}