Checked/Unchecked keywords in Visual Basic - by Kumba42

Status : 

  Other<br /><br />
		This item had a custom resolution.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 636564 Comments
Status Closed Workarounds
Type Suggestion Repros 0
Opened 1/17/2011 8:26:43 PM
Access Restriction Public


It would be wonderful if Visual Basic supported C#'s "checked" and "unchecked" keywords to disable integer overflow checks on a granular level.  I've found that in attempting to override GetHashCode in a project of mine, that sometimes I'll trip up an OverflowException because neither a Int32 or an Int64 is not large enough to hold a temporary numeric value for computing the hash of various fields.  I'm hoping to avoid using larger data types that can incur a speed penalty, but I am starting to run out of options.

Thus, if I had access to "checked" and "unchecked", which would allow the temporary hash variable to simply wrap back around to 0, life would be a lot easier.
Sign in to post a comment.
Posted by Lucian [MSFT] on 3/4/2011 at 3:02 PM
Hi Kumba. Thanks for your suggestion.

I agree that it would have made it possible to implement Jon's code. Without it, you're forced to use some other GetHashCode implementation.

Incidentally, I encourage you to read Jared Parson's blog posts on implementing GetHashCode:

I'll add "checked/unchecked" to our internal list of things we're considering for future versions of VB, with your bug number. The list so far is here:

We'll see how the discussion goes. My personal opinion is that it would be nice not to add new keywords+concepts to the language unless they have high value, and the value of "unchecked" seems pretty small. One of my colleagues had the neat idea of using the "Key" keyword as a modifier for fields+properties, so that the compiler could auto-generate an efficient GetHashCode using the same strategy as it does for anonymous types. I wonder what you'd think of that?

Thanks again,

Lucian Wischik, VB language PM
Posted by Microsoft on 1/17/2011 at 9:13 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(