This is part of the (relatively-new) "nullable reference types" feature:
Nullable reference types | Microsoft Docs[
^]
When enabled, the compiler assumes that any reference type must not contain
null
unless it is marked as "nullable" by appending
?
to the type name.
Technically, therefore, your method should be declared as returning:
(IEnumable<instance>?, IEnumable<instance>?)
Unless of course you could return a non-null enumerable with a null item, in which case it should be:
(IEnumerable<instance?>?, IEnumerable<instance?>?)
The "null forgiving operator" is intended for cases where the developer thinks they know better than the compiler - the static flow analysis cannot determine that the value is not
null
, but the developer is absolutely certain that it cannot be
null
. For example:
Lying to the compiler | Jon Skeet's coding blog[
^]
Unfortunately, that means it can be abused, as in this case: you've told the compiler that
null
is not
null
. :)