Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Your help please...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Your help please...

    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.
    Last edited by funk101; 05-26-2007, 10:15 PM.

    #2
    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)

    Comment


      #3
      Great!

      Thanks for your help.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      26 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      183 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      335 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      260 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X