2 ms·
> C# does not attach any special meaning to null in the context of lookup Lots of C# APIs do, in fact return null from Index (ie the [] operator) for "Not foun
by tialaramex 4y ago
> C# does not attach any special meaning to null in the context of lookup
Lots of C# APIs do, in fact return null from Index (ie the [] operator) for "Not found", you're clearly writing much newer .NET code and so you're using a modern generic container which can't do this (because its return type can't be null)
> nor does it allow it by default even for reference types (assuming that you're compiling with nullability checks on, which has been the default for years)
My emphasis. I believe the default you're talking about starts in .NET 6 in late 2021. I don't think "since late 2021" qualifies as "for years".
C# Code I write from scratch does have nullability checks because I'd prefer to be in a language where "Null reference" isn't a thing, and this is as close as C# gets - but I maintain tonnes of code that was written three, five, even ten years ago.
- int_19h 4y agoI've been writing C# code since 2002, when .NET 1.0 first came out. "Modern generic collections" have been around since .NET 2.0 - that's 2005, so almost 18 years now. Their use was already pervasive by 2010, in my experience. Just about the only place where I can think of finding old-style patterns like returning nulls is WinForms and WebForms APIs from that same era that implemented the non-generic interfaces like IDictionary, and which can't be changed for backwards compatibility reasons. I stand corrected on the timeline for nullable reference types being the default - for some reason I remembered it as being on by default for new projects since VS 2019.