C# うるう年であるかを判定する
C#で、うるう年であるかを判定するサンプルコードを記述してます。
環境
- OS windows11 pro 64bit
- Microsoft Visual Studio Community 2022 Version 17.2.6
うるう年であるかを判定
うるう年であるかを判定するには、「DateTime.IsLeapYear」を使用します。
using System;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
System.Console.WriteLine(DateTime.IsLeapYear(2020)); // true
System.Console.WriteLine(DateTime.IsLeapYear(2021)); // false
System.Console.WriteLine(DateTime.IsLeapYear(2022)); // false
}
}
}
実行結果
-
前の記事
javascript エラー「SyntaxError: ‘with’ statements are not valid in strict mode.」の解決方法 2022.09.02
-
次の記事
mac コマンドでログインしているユーザーとプロセスを確認する 2022.09.02
コメントを書く