Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Created February 10, 2020 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ufcpp/5dde1abd877c16c0e8f45e02c3858fe7 to your computer and use it in GitHub Desktop.
Save ufcpp/5dde1abd877c16c0e8f45e02c3858fe7 to your computer and use it in GitHub Desktop.
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