一段有意思的代码:
1 namespace TestHahaha 2 { 3 class Program 4 { 5 6 static void Main(string[] args) 7 { 8 A a = new A(); 9 a.Print();10 }11 12 }13 14 public class A15 {16 public B bObj = null;17 18 public A()19 {20 bObj = new B(this);21 }22 23 public void Print()24 {25 if (bObj == null)26 Console.Write("bObj == null");27 else28 Console.Write("bObj != null");29 }30 31 public void SetBNull()32 {33 bObj = null;34 }35 }36 37 public class B38 {39 public A aObj = null;40 41 public B(A a)42 {43 aObj = a;44 a.SetBNull();45 }46 }47 }
答案是:bObj != null;