繁体   English   中英

仅在DateTime中设置年份

[英]Set only the year in DateTime

嗨,我是Farley,刚接触C#,是的,我找到了其他答案,但不是我想要的。

所以我有一个Car类,我现在根据值断言。

PKW Kaefer = new PKW("VW", "Käfer", "K-GS-01", DATETIMEVALUEHERE, 9999, 1000, 30, 1);

该日期时间应该是汽车制造的年份。 这是我的问题,我只需要年份而不是其他任何东西,我也应该能够从中调用它

Console.WriteLine(Kaefer.Erstzulassung);

如果有人需要,这是我的汽车课

  public PKW(string hersteller,
        string modell,
        string kennzeichen,
        DateTime erstzulassung,
        double anschaffungspreis,
        double hubraum,
        int leistung,
        int schadstoffklasse
        )
        : base(hersteller, modell, kennzeichen, erstzulassung, anschaffungspreis)
    {
        this.Hubraum = hubraum;
        this.Leistung = leistung;
        this.Schadstoffklasse = schadstoffklasse;
    }

谢谢。

我的建议是仅使用整数代替。

int erstzulassung

DateTime结构是具有包含月,日和年一个结构。

实际上,不需要使用DateTime类。 因为,这更复杂,我的意思是您不需要DateTime提供的其他参数。 例如,天或月。 因此,这需要不必要的存储。 :) <3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM