Since C# 8.0 nullable reference types are possible. If they are enabled you have to append the ? to the reference type to make it nullable.
My question now is how can I force a method parameter that uses the params keyword, to be not-nullable.
Example:
#nullable enable
public void MyMethod(params int[] foo)
{
// foo can still be null
// How can I ensure that foo is not null at compile-time
}
MyMethod(null); // valid, but why?
Another question which is similar, would be: Why is params int[] foo even nullable in the first place? I would expect something like params int[]? foo to make it nullable. But with params this seems to be different.
I tried NotNullAttribute but this only gives a warning. I want to disallow that completely by the compiler.
Does anybody know a way to make it non-nullable and maybe can tell me why params allows nullable even with #nullable enable?