今日も C# 8.0 の新機能の話。 C# 8.0 の中でおそらく一番の目玉機能扱いになると思われる null許容参照型の話です。 参照型でもそのままでは null を認めない 要は、参照型に対しても、単にTと書くとnullを認めない型になり、 null許容にしたければT?と書くようにするという機能です。 #nullable enable // string には null が来ない // null が来ないなら s.Length で OK static int M1(string s) => s.Length; // string? には null が来る // null が来るのに s.Length (null チェックしてない)はダメ static int M2(string? s) => s.Length; // string? には null が来る // null が来ても ?

