24
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【C#】C#のバージョンと.NETのバージョンを確認する方法

Posted at

#C#のバージョン確認方法#
コードのどこかに**#error version**を入力する

↓こんな感じで入力すると
image.png

↓こんな風に、Visual Studio の警告に出てくる
image.png

これだと私の場合はC#8.0

#.NETのバージョン確認方法#
System.Runtime.InteropServices をusingして
RuntimeInformation.FrameworkDescriptionを参照すれば良い

using System;
using System.Runtime.InteropServices;

class Class1
{
    static void Main(string[] args)
    {
        Console.WriteLine(RuntimeInformation.FrameworkDescription);
    }
}

結果:

.NET Core 3.1.8

#参考#
https://docs.microsoft.com/ja-jp/dotnet/api/system.runtime.interopservices.runtimeinformation.frameworkdescription?view=net-5.0#System_Runtime_InteropServices_RuntimeInformation_FrameworkDescription

24
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?