Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
16.5 で修正される null 許容参照型がらみの問題
// 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