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

  • 相关阅读:
    Individual Project
    最后的作业
    Reading Task 2 —— by12061154Joy
    Code Review —— by12061154Joy
    Pair Project —— Elevator Scheduler
    《移山之道》Reading Task——by12061154Joy
    Individual Project
    qa_model
    个人阅读作业2
    Personal Reading Assignment 2 -读推荐文章有感以及项目开发目前总结
  • 原文地址:https://www.cnblogs.com/ibrahim/p/1353635.html
Copyright © 2011-2022 走看看