Created
February 10, 2020 01:54
-
-
Save ufcpp/5dde1abd877c16c0e8f45e02c3858fe7 to your computer and use it in GitHub Desktop.
16.5 で修正される null 許容参照型がらみの問題
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
// Visual Studio 16.5 で修正される null 許容参照型がらみの問題 | |
#nullable enable | |
using System.Diagnostics.CodeAnalysis; | |
class X<T> | |
where T : class | |
{ | |
[return:MaybeNull] | |
public T M() => null; // ここの null に警告出てた | |
[AllowNull] | |
public string P { get => _p; set => _p = value ?? ""; } | |
private string _p = ""; | |
} | |
class Program | |
{ | |
static void Main() | |
{ | |
var x = new X<string> | |
{ | |
P = null // ここの null に警告出てた | |
}; | |
x.P = null; // これなら 15.4 時点から警告出ない | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment