3 ms·
"unchecked" is the default in C#, and "checked" is opt-in, except for compile-time expressions (and System.Decimal, which always throws on overflow). You can t
by int_19h 5y ago
"unchecked" is the default in C#, and "checked" is opt-in, except for compile-time expressions (and System.Decimal, which always throws on overflow).
You can tell the compiler to use "checked" by default for a given project, but it's fairly rare to see that in practice.
I wish it was the other way around, but I guess they didn't consider the overhead of "checked" acceptable as a default back in 1999; and now it's a back-compat issue.
- pjmlp 5y agoIt is being discussed to change the defaults on .NET 7.
- int_19h 5y agoC# 11, rather? I wouldn't expect them to change anything on bytecode level, since the choice between wraparound and overflow is always explicit there. Do you recall where that discussion is taking place? I can't find a proposal to this effect in the usual GitHub repo.
- pjmlp 5y agoBecause the change is on the Visual Studio templates to set the checkbox enabled by default, no need to change the language for something it already supports. It was mentioned on one of the regular YouTube videos with the team, but I am failing to find it now.
- MaxBarraclough 5y agoThanks, I've edited that in.