110,571
社区成员
发帖
与我相关
我的任务
分享
public class A
{
private B _b = new B(this); //问题出在了 this 这里。
public B B
{
get
{
return _b;
}
}
}
public class B
{
private A _a;
public B(A a)
{
_a = a;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
public class A
{
private B _b;
public A()
{ _b = new B(this); }
public B B
{
get
{
return _b;
}
}
}
public class B
{
private A _a;
public B(A a)
{
_a = a;
}
}
class Program
{
static void Main(string[] args)
{
A a = new A();
Console.WriteLine(a.B);
}
}
}
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class A
{
private B _b;
public B B
{
get
{
return _b;
}
internal set
{
_b = value;
}
}
}
public class B
{
private A _a;
public B(A a)
{
_a = a;
_a.B = this;
}
}