我有这个代码,我不明白为什么如果前两行没有,最后一行会给我一个警告:
[return: NotNull]
public static IEnumerable<T> EmptyIfNull<T>(this IEnumerable<T>? sourceEnumerable) => sourceEnumerable ?? Array.Empty<T>();
public static void ConfigurationSectionTest(IConfigurationSection? cfg)
{
IEnumerable<IConfigurationSection>? myChildren = cfg?.GetChildren();
IEnumerable<IConfigurationSection> safeChildren = myChildren.EmptyIfNull();
IEnumerable<IConfigurationSection> safeChildren2 = cfg?.GetChildren().EmptyIfNull(); //Warning: Converting null literal or possible null value to non-nullable type.
}