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

  • SEARCH
  • Home
  • 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 7040025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:52:08+00:00 2026-05-28T01:52:08+00:00

So today I discovered that c# passes reference types by value by default. This

  • 0

So today I discovered that c# passes reference types by value by default. This ran counter to what I thought I understood – reference types are by reference as standard. Oh well.

This led me to think about a method that I had that took an entity object as a parameter, attached to a context, and made some changes to it. The method did not return the object. When calling save changes on my context, the changes made within the method were applied.
I assumed at the time that it worked because I was passing a reference to the object and so could happily alter it without having to return anything to reassign.

So the question is, how does this work? (the code did work as I expected).

Thanks,

  • 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-28T01:52:08+00:00Added an answer on May 28, 2026 at 1:52 am

    Yes, this stuff is tricky. I’ve found myself not thinking about it for a few months, and then having to think about it for a few seconds to get it straight in my head again. Even though I’ve understood it for a long time.

    Even though the parameter is by value, that just means that a new reference variable is created, but still pointing to the same object. If you make the parameter by reference, then the same pointer would be passed in, which of course points to the same object.

    It makes a difference when you mess with the parameter variable. If you set it to null or to some other object, the variable “outside” will not be affected. But if the parameter was passed in by value, then setting the variable to null or another object will alter the reference “outside”.

    For a value type, whether the parameter is by reference or by value makes a practical difference more often. Changes to the value or to a member (if it’s a struct) will not be reflected “outside” if passed by value.

    Here’s a good explanation with easy examples.

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

Sidebar

Related Questions

Today, I discovered that using Collections.synchronizedXXX doesn't play well with reflection. Here's a simple
I discovered today in iReport that I cannot set the initial value expression of
Today I discovered that my fresh installation of Apache HTTP Server is able to
Today I discovered something that makes me sad: objects of type System.Generic.Collections.List don't have
Today, I ran into this weird problem with a user using Mac OS X.
I discovered today that I can switch back to a branch even after I
Not long time before I've discovered, that new dynamic keyword doesn't work well with
i discovered today that Windows 7 comes with a very impressive MathPanel utility, for
So we went to implement something today, and discovered that there already is several
I discovered(*) today that, depending on the server, my TSQL commands were case-sensitive, meaning

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.