3 ms·
It's horrible. For example, it treats Linq's .First() as nullable. (.First() throws an exception, .FirstOrDefault() returns null.) Type.Name is also treated a
by gwbas1c 5y ago
It's horrible.
For example, it treats Linq's .First() as nullable. (.First() throws an exception, .FirstOrDefault() returns null.)
Type.Name is also treated as nullable.
I didn't encounter any issues like that when I tried Swift and Rust.
- Genbox 5y agoThat 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();