Using VS 2022, .Net 6.0, I thought this was correct :
public static void test(List<String> list = null)
{ }
but compiler warns me :
CS8625 Cannot convert null literal to non-nullable reference type
List<T>
should be nullable by definition, right?
Recently, Microsoft enabled nullable reference types by default on new projects.
You have five ways to make this warning go away:
public static void test(List<String>? list = null) { }
!
operator. (I like to call this the "I know better" operator because I will typically use it when I know what I'm assigning is not null but the compiler thinks it could be.)public static void test(List<String> list = null!) { }
#nullable disable
public static void test(List<String> list = null) { }
#nullable restore
#nullable disable
at the beginning of it (with your namespace declaration)