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是如何识别内存堆上被引用的变量?

  • 相关阅读:
    牛客练习赛16
    AtCoder Regular Contest 096
    基础实验4-2.8 部落 (25分)--并查集
    进阶实验4-3.3 完全二叉搜索树 (30分)
    进阶实验4-3.2 Windows消息队列 (25分)--建堆
    基础实验4-2.5 关于堆的判断 (25分)---建小顶堆
    基础实验4-2.4 搜索树判断 (25分)--二叉搜索树
    基础实验4-2.1 树的同构 (25分)--二叉树
    案例4-1.7 文件传输 (25分)--并查集
    进阶实验3-3.1 求前缀表达式的值 (25分)--堆栈
  • 原文地址:https://www.cnblogs.com/ibrahim/p/1353635.html
Copyright © 2011-2022 走看看