Feedback

Herausfinden, ob ein Jahr ein Schaltjahr ist

Sprache: C#

Gibt's zwar schon für VB, aber für C# eben noch nicht, deshalb hier eine kurze Methode, die bestimmt, ob ein bestimmtes Jahr ein Schaltjahr ist.
private bool IsLeapYear(DateTime dt)
{
    bool mod4 = dt.Year % 4 == 0;
    bool mod100 = dt.Year % 100 == 0;
    bool mod400 = dt.Year % 400 == 0;

    return (mod4 && (!mod100 || mod400));
}
private bool IsLeapYear(DateTime dt)
{
    bool mod4 = dt.Year % 4 == 0;
    bool mod100 = dt.Year % 100 == 0;
    bool mod400 = dt.Year % 400 == 0;

    return (mod4 && (!mod100 || mod400));
}

3 Kommentare