-
Is this a Visual Studio Problem, C# Problem or is that allowed behaviour? This Code compiles and runs, resulting in a list with one entry that is null, even though the List accepts only non nullable strings. string? testString = null;
List<string> testList = [testString]; This code does not compile: List<string> testList3 = new List<string> { null };
List<string> testList4 = new List<string>();
testList4.Add(null); We are using the Roslyn analyzer.
I think that's a bug? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Both snippets of code compile successfully. The C# compiler will issue warnings about potential nulls, but it is not a compiler error. Are you using a third-party analyzer in Visual Studio, like R#? That might be giving you the errors on the second code snippet. |
Beta Was this translation helpful? Give feedback.
-
This looks like dotnet/roslyn#71522, @RikkiGibson to confirm. |
Beta Was this translation helpful? Give feedback.
-
There are about five different ways to insert |
Beta Was this translation helpful? Give feedback.
-
This is one of the remaining work items in dotnet/roslyn#68786:
|
Beta Was this translation helpful? Give feedback.
This is one of the remaining work items in dotnet/roslyn#68786: