簡體   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