Created
May 15, 2019 02:41
-
-
Save ufcpp/440d29fe9e94805b4ea4198d2f6093c9 to your computer and use it in GitHub Desktop.
#nullable ディレクティブの初期挙動
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// #nullable ディレクティブの初期挙動。 | |
// VS 16.2 の辺りで実装変わりそう。 | |
class Program | |
{ | |
static void Main() | |
{ | |
#nullable enable | |
// 警告きっちり出すモード | |
string s1 = null; // この行に CS8600 警告 | |
int i1 = s1.Length; // この行にも CS8602 警告(W-warning 状態) | |
#nullable safeonly | |
// CS8600 (converting nullable to non-nullable)だけ無視するモード | |
// (なくなる予定。#pragma warning disable CS8600 で代用が効く) | |
string s2 = null; // ↓の警告が出るんだったらこの行の警告なくても困らないよね? | |
int i2 = s2.Length; // この行に CS8602 警告 | |
#nullable disable | |
// 旧来のモード(警告なし) | |
string s3 = null; | |
int i3 = s3.Length; // この行にも警告出ない | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment