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

  • 相关阅读:
    深度学习模型参数计算
    keras多输出多输出示例(keras教程一)
    keras可视化报错:OSError: `pydot` failed to call GraphViz.Please install GraphViz问题解决
    git版本管理,git tag
    python封装自己的模块,pip install安装到python环境
    如何理解Virtual DOM
    使用 Hbuilder 连接手机调试移动端项目
    js 常用排序
    博客漂浮的小人
    开发者必备Linux命令
  • 原文地址:https://www.cnblogs.com/ibrahim/p/1353635.html
Copyright © 2011-2022 走看看