Announcement

Collapse
No announcement yet.

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.

    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.

            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 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