RaynorWolfcastle
Diamond Member
I'm having trouble passing a 2-D ArrayList into another class. The snippet of code I'm using is as follows:
class GraphConstruction
{
public GraphConstruction(Graphics grfx, Size size, Point pt)
{
this.grfx = grfx;
this.graphSize = size;
this.graphLocation = pt;
}
public void DisplayIt()
{
ArrayList tempData = new ArrayList();
tempData.Add(new DateTemp(new Date(1,1,1800),10));
ArrayList multTempData = new ArrayList();
multTempData.Add(tempData);
GraphBG grph = new GraphBG(grfx, Color.Black,graphSize, graphLocation);
GraphData gData = new GraphData(grfx, Color.Black, multTempData);
grph.DisplayIt();
gData.DisplayIt();
}
protected Graphics grfx;
protected Size graphSize;
protected Point graphLocation;
}
class GraphData : GraphComponents
{
public GraphData(Graphics grfx, Color clr)
{
this.grfx = grfx;
this.clr = clr;
}
public GraphData(Graphics grfx, Color clr, ArrayList DataPoints)
{
this.clr = clr;
this.grfx = grfx;
this.dataPoints = DataPoints;
}
public override void DisplayIt()
{
grfx.DrawString(dataPoints[0][0].ToString(), new Font("Arial",12), new SolidBrush(Color.Black), 20, 20);
}
private Color clr;
private Graphics grfx;
public ArrayList dataPoints;
}
I omitted a bunch of code that is more or less relevant to this. ToString() is appropriately overriden for the DateTemp class.
the underlined part is what causes the error, the compiler tells me: "Cannot apply indexing with [] to an expression of type object"
The error does not occur if I pass in a 1-D ArrayList and adjust all the code appropriately. Oddly enough, the debugger has no problem showing me the string's value when I monitor the value of dataPoints[0][0].ToString()
Judging by the message, it seems that this is a casting problem, though I have not been able to solve it
If you're wondering what I'm trying to do:
What I want to do is (eventually) allow the user to add as many data series of DateTemps as he wants, I figured that using a 2-D ArrayList would be the best way.
Let me know if you know how I could solve this problem and/or have a suggestion that may help.
As always any help is greatly appreciated,
-Ice
*edited for readability but the forum removes all the tabs so there's only so much I can do 😱
class GraphConstruction
{
public GraphConstruction(Graphics grfx, Size size, Point pt)
{
this.grfx = grfx;
this.graphSize = size;
this.graphLocation = pt;
}
public void DisplayIt()
{
ArrayList tempData = new ArrayList();
tempData.Add(new DateTemp(new Date(1,1,1800),10));
ArrayList multTempData = new ArrayList();
multTempData.Add(tempData);
GraphBG grph = new GraphBG(grfx, Color.Black,graphSize, graphLocation);
GraphData gData = new GraphData(grfx, Color.Black, multTempData);
grph.DisplayIt();
gData.DisplayIt();
}
protected Graphics grfx;
protected Size graphSize;
protected Point graphLocation;
}
class GraphData : GraphComponents
{
public GraphData(Graphics grfx, Color clr)
{
this.grfx = grfx;
this.clr = clr;
}
public GraphData(Graphics grfx, Color clr, ArrayList DataPoints)
{
this.clr = clr;
this.grfx = grfx;
this.dataPoints = DataPoints;
}
public override void DisplayIt()
{
grfx.DrawString(dataPoints[0][0].ToString(), new Font("Arial",12), new SolidBrush(Color.Black), 20, 20);
}
private Color clr;
private Graphics grfx;
public ArrayList dataPoints;
}
I omitted a bunch of code that is more or less relevant to this. ToString() is appropriately overriden for the DateTemp class.
the underlined part is what causes the error, the compiler tells me: "Cannot apply indexing with [] to an expression of type object"
The error does not occur if I pass in a 1-D ArrayList and adjust all the code appropriately. Oddly enough, the debugger has no problem showing me the string's value when I monitor the value of dataPoints[0][0].ToString()
Judging by the message, it seems that this is a casting problem, though I have not been able to solve it
If you're wondering what I'm trying to do:
What I want to do is (eventually) allow the user to add as many data series of DateTemps as he wants, I figured that using a 2-D ArrayList would be the best way.
Let me know if you know how I could solve this problem and/or have a suggestion that may help.
As always any help is greatly appreciated,
-Ice
*edited for readability but the forum removes all the tabs so there's only so much I can do 😱