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

相关文章:

  • 2021-08-05
  • 2021-06-19
  • 2021-09-16
  • 2022-12-23
  • 2021-11-20
  • 2021-10-05
  • 2021-07-09
  • 2022-01-19
猜你喜欢
  • 2022-01-16
  • 2022-12-23
  • 2021-10-12
  • 2021-11-08
  • 2021-05-14
  • 2021-06-27
  • 2022-12-23
相关资源
相似解决方案