#nullable

2025-07-02

Was fällt euch auf? Ist das wirklich sinnvoll so?
Diskutiert mal! 👀

Bitte denkt selbst nach und fragt nicht einfach eine KI – eure eigenen Ideen interessieren mich viel mehr!

#CSharp #dotnet #fail #dotnetperle #cleancode #boolLogic #CodeReview #nullable #bug

CSharp Code:

bool? zeichenOption = /* Wert zuweisen, z.B. true, false oder null */;

if (!zeichenOption.HasValue && !zeichenOption.GetValueOrDefault())
{
    Console.WriteLine("9106 | 2 | true");
}
else
{
    Console.WriteLine("9106 | 3 | true");
}
2024-12-21

@badcel @khalidabuhakmeh I guess I'm not fully understanding what #nullable does then, since it clearly does not mean things can't be null, at least not in all contexts.

I did use `where T: notnull` now and the error also goes away. But in my mind, that should be the default when #nullable is enabled.

Marcel T. : :gnome: :dotnet:badcel@fosstodon.org
2024-12-21

@mortoray @khalidabuhakmeh I think it is a bit confusing because T could either be a reference type or a value type. Value types having a completely different nullability mechanic which is not at all related to #nullable pragma. If you exclude structure types via : “ where T : class” the warning goes away, too and the class should behave as expected as it does not need to care for structs anymore.

2024-12-21

@khalidabuhakmeh But yes, nonetheless, declaring it nonnull does fix the problem.

`class Something<T> where T : notnull`

But I still don't understand why. It seems to go against what `#nullable enable` means.

2024-12-21

@khalidabuhakmeh But I have `#nullable enable` on the file, implying all references are non-null unless declared otherwise, like `T?`.

Also, if I mark source as `T? source` then I get errors in my code, implying that it isn't actually nullable, except in this circumstance.

Brad Wilsonbradwilson
2024-07-30

@andrewlock I see you enabled nullable, which is quite a minefield with a source-only package that wants to be able to work not only with nullable on or off, but also in a language where nullable isn't an option.

You end up with stuff like this:

github.com/xunit/assert.xunit/

github.com/xunit/assert.xunit/

You can't just " disable" because the compiler might not support it. So if they enable nullable but forget to "tell you", then you have to turn off a bunch of nullable "violations".

Brad Wilsonbradwilson
2024-05-28

This is super duper extra important.

C# Nullable Reference Types are a compile-time thing, not a runtime thing. "string?" and "string" are both just "string" at runtime.

This means:

- Always guard against your users passing `null` even for types that _shouldn't_ allow it, because it's *not a runtime guarantee*.

- You can't create overloads that differ only on nullability (i.e., Method(string) vs. Method(string?)) because *they're the same type at runtime*.

Egil Hansenegil
2024-04-09

Hey @jasonbock, excellent walkthrough on source generators in youtube.com/watch?v=KTsyS3rDUgg.

You don't need to restart VS to observe changes to a source generator in another project. A `dotnet build-server shutdown` at the command line resets the build-server cache and forces the generators to re-run from scratch.

Wrt. to nullable, I typically wrap generated code in ` annotation`/` restore`. Then I do not have to use the damn-it operator.

2023-08-19

@anthony_steele for DTO's I'll take a "#nullable disable"

2023-08-19

for #dotnet people, when we have #nullable checking on, how do you feel about DTO fields initialised to " = null!;"
e.g.

public string Name { get; set; } = null!;

It seems wrong to me "Name is not nullable, and also, surprise, it's null!"

It seems like that could go wrong.
But if it's the accepted idiom than I'll go with it.

Is there a better one?
"= string.Empty;" is verbose.

What do you think?

PxtlPxtl
2023-05-06

@khalidabuhakmeh like with " disable" or in VB.net "option strict" and "option explicit".

2023-04-12

I'm being punished.

I've done something to anger the gods. lol

#linq #dotnet #nullable #hell

2023-04-12

I am dying of nullable type-itis.

#linq #dotnet #nullable #hell

2023-04-05

ASP.NET Core,やっぱまだあちこちに #nullable disable が残ってるなぁ

2023-02-09

Maybe not that controversial take, but I love the nullable feature in C#. There are occasional situations where the nullable warning appears and I'm like "why???" But all in all, it has been a great help, and has generally made me a better programmer, even when doing stuff with .NET Framework.

#dotnet #csharp #nullable #coding

2023-01-20

#CSharpForMarkup 2 for #WinUI3 and @unoplatform is coming along nicely🙂

-🔥Windows C# #hotreload updates UI on Ctrl+S
- All #dotnet 7 target platforms, #csharp 11
- Nested view files in sln explorer
- Fully #nullable + #editorconfig enabled dotnet new template

UI Markup in C# side by side with running UIFile nesting for views in Solution ExplorerUpdate UI automatically in Windows on C# Hot Reload with Ctrl+S
2022-07-07

Is there a recommended pattern to follow when dealing with #nullable types in #TypeScript ?

This snippet is just from the #supabase #nextjs quickstart guide. Since data maybe null when fetched from the Supabase bucket, TS complains since createObjectURL requires the parameter.

I know that I could guard the line with an "if" statement but that just seems unnecessary. Like there should be a more elegant solution, something like optional chaining. :thinking: :javascript: :react:

えあい:win98_shrimp::straight_shrimp::win98_shrimp:Eai@stellaria.network
2022-06-04

#nullable enableどこにおけばいいんだ

えあい:win98_shrimp::straight_shrimp::win98_shrimp:Eai@stellaria.network
2022-06-04

staticけして#nullable つけたらちゃんと怒られた

2019-12-24

まあC#8.0なら#nullable enableあるけど

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst