首页 > 其他分享 >奇怪现象,父类构造函数中的赋值子类无法取得

奇怪现象,父类构造函数中的赋值子类无法取得

时间:2023-03-17 20:13:36浏览次数:37  
标签:int 子类 Father protected nothing 父类 Shize public 构造函数

实战中这样的类,Shize保持了原始值, 但单元测试,又是好的,很奇怪。

public abstract class GrandPa 
{
    protected int Nothing;
    protected GrandPa(int nothing)=> Nothing = nothing;

}

public abstract class Father : GrandPa
{
    protected readonly long Shize;
    protected Father(int nothing): base(nothing)
    {
        Shize = DateTime.Now.ToTimeStampInSecond();
    }
}
public class Son : Father
{
    public Son(int nothing) : base(nothing)
    {
    }
    public long GetShiZe() => Shize;
}

标签:int,子类,Father,protected,nothing,父类,Shize,public,构造函数
From: https://www.cnblogs.com/occulter/p/17227999.html

相关文章