zoukankan      html  css  js  c++  java
  • 【讨论】.net是如何识别内存堆上的被引用的变量?

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace List
    {
        public class Node<T>
        {
            private T data;
            private Node<T> next;
            public Node(T val)
            {
                data = val;
                next = null;
            }
            public Node()
            {
                data = default(T);
                next = null;
            }

            public T Data
            {
                get { return data; }
                set { data = value; }
            }
            public Node<T> Next
            {
                get { return next; }
                set { next = value; }
            }
        }

        class Program
        {
            static void Main(string[] args)
            {
                Node<int> node0 = new Node<int>(1);
                Node<int> node1 = new Node<int>(2);
                Node<int> node2 = new Node<int>(3);
                Node<int> node3 = new Node<int>(4);

                node0.Next = node1;
                node1.Next = node2;
                node2.Next = node3;

                Node<int> current = node0;
                Node<int> temp = current.Next;
                current.Next = current.Next.Next;

                Console.WriteLine("temp=" + temp.Data.ToString());
                          
                Console.Read();
            }
        }
    }

    大家先猜猜打印结果是什么?

    其实其结果让我很迷惑,然后让我产生了一些联想。.net是如何识别内存堆上被引用的变量?

  • 相关阅读:
    堆内存内部结构
    JVM 总体结构
    HTTP的工作原理
    HTTP协议简介
    服务器硬件资源_I/O
    maven常用命令行总结
    java enum—枚举的应用
    JAVA闰年的判断
    JAVA数据结构与算法——求最大公约数!!
    ThinkPHP 分页
  • 原文地址:https://www.cnblogs.com/ibrahim/p/1353635.html
Copyright © 2011-2022 走看看