Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

adding to a list passed as a parameter in a Method

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

    adding to a list passed as a parameter in a Method

    If I have a method that has a list as a parameter:-

    Code:
    private void myMethod(List<orderList> someList)
    {
         someList.Add(someOrderItem);
    }
    And I call the method passing in a list:-

    Code:
    myMethod(myOrderList);
    Will the items be added to myOrderList, I suspect not?

    if this is the case what is the best way to achieve this?

    #2
    Hello,

    Thank you for the question.

    I wanted to clarify what you are trying to do.

    you have the method:

    Code:
    private void myMethod(List<orderList> someList)
    {
         someList.Add(someOrderItem);
    }
    and you call the method and provide a list to it.

    Code:
    myMethod(myOrderList);

    in the method, someList is == to myOrderList as you provided it by calling the method.

    Is the end result to add myOrderList items into a list using the method myMethod?

    Or is this to add the item someOrderItem into the list myOrderList?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      The end result I want is to add someOrderItem into the list myOrderList.

      Comment


        #4
        Originally posted by GKonheiser View Post
        The end result I want is to add someOrderItem into the list myOrderList.
        Lists are passed by reference. That should add to the list as requested. Is your experience otherwise?

        Comment


          #5
          To be honest I'm not sure yet. I'm seeing some results that would suggest other wise but it could be something else. I will debug with Visual Studio tomorrow and see whats going on. Thanks for your input.

          Comment


            #6
            Hello,

            Thank you for the details.

            If you are getting unexpected output when you test this, please let me know and I would be happy to assist in finding what is going wrong.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              I found the problem. The listed I passed to the method was indeed getting populated. But later in the method I had a misplaced semi-colon after an if statement that was causing the list to be emptied, so thx again for the help : )

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by hdge4u, 04-29-2024, 12:23 PM
              5 responses
              28 views
              0 likes
              Last Post MisterTee  
              Started by llanqui, 01-25-2024, 06:15 PM
              9 responses
              64 views
              0 likes
              Last Post MisterTee  
              Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
              16 responses
              65 views
              0 likes
              Last Post tradingnasdaqprueba  
              Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
              55 responses
              5,463 views
              0 likes
              Last Post BartMan
              by BartMan
               
              Started by DawnTreader, 05-08-2024, 05:58 PM
              16 responses
              52 views
              0 likes
              Last Post DawnTreader  
              Working...
              X