PDA

View Full Version : Your help please...


funk101
05-26-2007, 10:12 PM
If you could help me out, I would appreciate it:

I have an ArrayList that I add elements to via a class like so:

...
private ArrayList myList;
...

public void ListManager()
{
myList.Add(new MyData(myTag, Close[0], myX, Close[0]));
}


public class MyData
{
public string tag;
public double price;
public double x;
public double y;
public MyData()
{
}
public MyData(string tag, double price, double x, double y)
{
this.tag = tag;
this.price = price;
this.x = x;
this.y = y;
}
}

Ok, when I iterate using a foreach loop:

foreach (object o in myList)
{
Print(o.ToString());
}

My output is:
NinjaTrader.Indicator.MyMarketProfile3+MyData

It is giving me what I requested, which is the MyData object, however, I would like to access the vars within MyData like so:

MyData.tag;
MyData.price;
etc.

I've tried o.tag; o.price;

...I can't for the life of me find out the correct syntax! Please shed light.

NinjaTrader_Dierk
05-26-2007, 10:48 PM
Several issues:
- it's C# convention to code public members starting with a capital letter ("Price")
- you declared "o" as of type "object" and not type "MyData". Try
foreach (MyData o in myList)

funk101
05-26-2007, 10:53 PM
Thanks for your help.