1.3.18 #
解答 #
删除该结点的下一个结点。
如下图,没有任何结点指向 y 结点,失去了所有引用的 y 结点会被 GC 清理掉。
代码 #
var x = new Node<string>();
x.Item = "first";
var y = new Node<string>();
y.Item = "second";
x.Next = y;
var z = new Node<string>();
z.Item = "third";
y.Next = z;
Console.WriteLine("x: " + x.Item);
Console.WriteLine("x.next: " + x.Next.Item);
x.Next = x.Next.Next;
Console.WriteLine();
Console.WriteLine("x: " + x.Item);
Console.WriteLine("x.next: " + x.Next.Item);