gpt4 book ai didi

C# base() 构造函数顺序

转载 作者:IT王子 更新时间:2023-10-29 04:46:31 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
C# constructor execution order

class Foo
{
public int abc;
Foo()
{
abc = 3;
}

}

class Bar : Foo
{
Bar() : base()
{
abc = 2;
}
}

在上面的例子中,当Bar对象被创建时,BarObject.abc的值是多少?是先调用基础构造函数,还是运行 Bar(),/然后/调用 base() 构造函数?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com