Home Dashboard Directory Help
Search

Checked/Unchecked keywords in Visual Basic by Kumba42


Status: 

Closed
 as Other Help for as Other


3
0
Sign in
to vote
Type: Suggestion
ID: 636564
Opened: 1/17/2011 8:26:43 PM
Access Restriction: Public
0
Workaround(s)
view

Description

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.
Details
Sign in to post a comment.
Posted by Microsoft 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:
http://blogs.msdn.com/b/jaredpar/archive/2008/04/28/properly-implementing-equality-in-vb.aspx
http://vbfeeds.com/post.aspx?id=5485

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:
http://blogs.msdn.com/b/lucian/archive/2010/01/28/what-didn-t-get-into-vb10.aspx

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(http://support.microsoft.com)
Sign in to post a workaround.