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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      578 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X