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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:54:23+00:00 2026-06-16T11:54:23+00:00

I have a class Simple , which contains an integer, number . Using this

  • 0

I have a class Simple, which contains an integer, number.
Using this code:

Simple b = new Simple();
List<Simple> list = new List<Simple>();
list.Add(b);
b.number = 6;
b = null;
Debug.WriteLine("The value of b is " + b);
Debug.WriteLine("And the value of the clown in the list is " + list[0].number);

The Debugs return The value of b is and And the value of the clown in the list is 6.

I can assume that by adding b to the list, then a reference to b is stored. Then, by nulling b, list still contains a reference to the object that was b and thus can print out the value of number.

However, if I can change a member of b and have that reflected by the reference stored in the list, then why doesn’t the b = null reflect on the value of list[0]? I can only assume this has something to do with value and reference.

Help anyone?

  • 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-16T11:54:25+00:00Added an answer on June 16, 2026 at 11:54 am

    b and list[0] are both variables that reference the same location in memory. When you set b = null, you’re setting b‘s reference to null. list[0] is still pointing to the original location in memory and is unchanged.

    When you change a property of b, (for instance b.A) you’re effectively saying

    Get whatever object b is pointing to and update property A.

    When you access A via list[0], you’re saying

    Go get whatever list[0] is pointing to and get me the A property.

    EDIT: As another example, if b = someObject and list[0] = someObject, setting b = someOtherObject will not change list[0]… list[0] is still pointing to someObject.

    So, to answer your question, you’d have to set b = null and list[0] = null to “null” the object they’re both referencing. Even that, though, doesn’t do what it seems like you want. All that will do is orphan the object in memory and allow the Garbage Collector to clean it up whenever it gets around to it.

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

Sidebar

Related Questions

I have this static class which contains a static variable (a simple int). I've
I have a static class called Helpers which contains a good number of simple
I have simple class with width and height member fields which define number of
I have created a simple class which contains three properties ID Name Amount i
My question is quite simple I have a class which contains a (private) object
I have defined a simple private class named SetOb which contains an int and
I have a relatively simple class which deletes a post: function delete_post($postid, $reason){ //Stuff
I have a simple class for use on JNI, which i need to export
So i have a class name repository which is just a simple array.Here is
I have a simple Java class in which I invoke a call to a

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.