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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:40:07+00:00 2026-05-12T10:40:07+00:00

I am really confused about object relationships! I have two classes Person and Address.

  • 0

I am really confused about object relationships!
I have two classes Person and Address. Here are the details:

 public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }

        private List<Address> _addresses = new List<Address>(); 

        public void AddAddress(Address address)
        {
            _addresses.Add(address);
            address.Person = this; 
        }

        public List<Address> Addresses  
        {
            get { return _addresses; }
            set { _addresses = value; }
        }
    }

  public class Address
    {
        public string Street { get; set; }


        public Person Person
        {
            get; set;
        }
    }

The AddAddress method in the Person class adds the address to the Addresses collection and also sets the Person for the Address object. Now, in the code I do the following:

var person = new Person() { FirstName = "John", LastName = "Doe" };
            person.AddAddress(new Address() { Street = "Blah Blah" });

            person.Addresses[0].Person = null; 

I am thinking that it should set the person object to null since Addresses[0].Person is pointing to the original person object. But it is not setting it to null. What is going on here?

  • 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-12T10:40:08+00:00Added an answer on May 12, 2026 at 10:40 am

    What is going on here?

    Simple Explanation:

    A variable, in this case ‘Person’, holds a reference to the object. Under the hood, this is just a number. When you assign it to null, what you are doing is just stopping that variable pointing at the object. The object itself still exists.

    — Edit

    A way to understand how this works, is to literally stand near your computer, and point at it. You are now a variable, and your computer is an object. Now stop pointing at the computer (put your arm down). Now you are a variable that has been assigned null. The computer still exists, nothing has changed about it, the only difference is that you now no-longer point at it.

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

Sidebar

Related Questions

I am bringing out a separate question from here . It really confused me.
i'm really confused about something and need some advice. i want to be able
I'm confused about how to use set_error_handler() properly, and the php documentation isn't really
Hey everybody, I'm very confused about how to use two different Cell Types in
I am reading WIX script written by others. There are some code really confuses
Really simple question - how do I do a search to find all records
Really stuck on trying to write code to unzip a file or directory on
Really my question has more to do with the server-side scrubbing of html that's
I really feel that I should learn Lisp and there are plenty of good
I really like DevX components, but they are pretty expensive, maybe anyone knows free

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.