Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6338407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:26:18+00:00 2026-05-24T19:26:18+00:00

I have a method that takes List<Foobar> and Foobar as parameters. Foobar is a

  • 0

I have a method that takes List<Foobar> and Foobar as parameters. Foobar is a regular class with private variables, a constructor, and methods to operate on the data.

I modify both of the instances passed in the method but for some reason I have to pass Foobar with the ref keyword or else the changes do not stick when the method completes. I do not have to do this for the list.

I’ve noticed this a couple times recently in my programming. Usually when passing an instance of a class to the method, modifying it changes the instance, but sometimes it doesn’t and it requires the ref keyword for changes to stick. It seems rather random in when it works. Does anyone know why this is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:26:19+00:00Added an answer on May 24, 2026 at 7:26 pm

    If the value of a parameter change, like this:

    parameter = new SomeValue();
    

    then that change will only be seen by the caller using ref.

    If instead you’re changing the contents of an object which the caller passed a reference to, then that reference can be passed by value:

    public void AppendHello(StringBuilder builder)
    {
        // This changes the data within the StringBuilder object that the
        // builder variable refers to. It does *not* change the value of the
        // builder variable itself.
        builder.Append("Hello");
    }
    

    See my article on parameter passing for more information.

    Note that if the parameter type is a struct instead of a class, then you won’t be passing a copy of the reference to an object – you’ll be passing the actual data itself. In that situation you’d need to use ref as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that takes a list of entities ( Class es) and
I have a Filter Method in my User Class, that takes in a list
I have a method that takes a List<int> , which is a list of
Assuming I have a class with a method that takes a System.Linq.Expressions.Expression as a
I have a python method that takes a list of tuples of the form
I have a search method that takes a list of ID's and I wish
I have a method that takes a list of SResource objects public static List<STriple>
If you have a method that needs to be tested that takes a list
I have the following extension method that takes a List and converts it to
i have a simple method that takes a generic List parameter but for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.