73 days ago · Tech · hide · Fediverse post

Take a look at this line of code: if (cmd.Def?.ColumnDef is not { } column) { return; } // do something with column Do you understand it? Would you write something like that? This is using the relatively new pattern matching behavior in C# and basically says "if ColumnDef is not a not null object that would otherwise be stored in a column variable, return". If your brain hurt at the "not a not null" part, you are not alone. Normally I would have written this differently: var column = cmd.Def?.ColumnDef; if (column is null) { return; } // do something with column There is a difference, though? Can you see it? Read the title of the post. Do you see it now? The difference is in the type of the column variable in the two cases. The first matches anything that is not null to column, so column will be non-nullable there. In the second block, column will have the nullable version of whatever type ColumnDef was. So if ColumnDef is a string (reference type) column is string in the first case…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town