I've a .NET 6 project with non-nullable reference types.
I want to constrain the objects parameter to a non-nullable array of nullable objects.
I've 4 possible methods and assume one of these should work.
public void Method1(object[] objects)
public void Method2(object[]? objects)
public void Method3(object?[] objects)
public void Method4(object?[]? objects)
Method2 and 4 both accept a null. So I'm left with 1 and 3 but I get a warning on both:
CS8625 Cannot convert null literal to non-nullable reference type
I would expect method3 to work without warning:
Method3(new object[] { null });
Is there any way to get this done?
My question is answered in one of the comments. I should of course have used:
Method3(new object?[] { null });