3 ms·
That is not true. LINQ's First() correctly returns a non-nullable type: https://source.dot.net/#System.Linq/System/Linq/First.cs,11 https://source.dot.net/#Sys
by Genbox 5y ago
That is not true.
LINQ's First() correctly returns a non-nullable type: https://source.dot.net/#System.Linq/System/Linq/First.cs,11 https://source.dot.net/#System.Linq/System/Linq/First.cs,11
FirstOrDefault() correctly returns a nullable type: https://source.dot.net/#System.Linq/System/Linq/First.cs,33 https://source.dot.net/#System.Linq/System/Linq/First.cs,33
typeof(type).Name is MemberInfo.Name, which is also not nullable: https://source.dot.net/#System.Private.CoreLib/MemberInfo.cs,14 https://source.dot.net/#System.Private.CoreLib/MemberInfo.cs...
I checked both .NET 5 and .NET 6. They have identical nullability.
- gwbas1c 5y agoThen how come I get a compiler error if I don't check the result?
- int_19h 5y agoDid you perhaps enable null checking for an older version of the framework (in which the standard assemblies don't have the appropriate annotations)? This works just fine when targeting .NET 6: object[] xs = {}; var n = xs.First(); n.ToString();