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 7894653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:27:03+00:00 2026-06-03T07:27:03+00:00

when I do: var foo = new Customer(Peter); var sth = foo; var foo2

  • 0

when I do:

var foo = new Customer("Peter");
var sth = foo;
var foo2 = foo;

and then:

foo = new Customer("Dave");

only foo is updated and the others will still be “Peter”.

But when I do:

foo.Name = "Dave";

then all the objects are updated. Why is this?

  • 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-06-03T07:27:05+00:00Added an answer on June 3, 2026 at 7:27 am

    When it comes reference types the variable (foo in your example) stores only the reference. When you assign new value to variable you’re changing only this variable, not an object it referenced before.

    class Customer
    {
        public Customer(string name)
        {
            Name = name;
        }
        public string Name { get; set; }
    
        public static Customer Current { get; set; }
    }
    

    The behavior you expect could be done with above code. If you set Customer.Current to some value then every code that asks for Customer.Current will get previously set Customer. However, static variables are usually not good design choice and come with their set of problems (testability, threading issues, etc.).

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

Sidebar

Related Questions

Which do you prefer? var foo = new Foo(); foo.Prop1 = 1; foo.Prop2 =
How can i concatenate var names to declare new vars in javascript?: var foo
void Foo() { string ID = test; var testctrl = new Control() {ID =
I have a System.Uri, e.g., var uri = new Uri(http://www.domain.com/foo/bar); How do I get
Suppose I have an anonymous class instance var foo = new { A =
I am able to use WinForms controls, but not an entire form: var foo
If I declare an object as follows: var foo.bar = new Object; Does that
Let's say I have a Dictionary<string,object> like so: var foo = new Dictionary<string, object>();
With : var Foo = new[]{ new {Something = 321}}; Why can I do
I have this object, dive : var dive = new Foo.Bar(); And Foo.Bar looks

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.