I'm converting to VB.NET, which doesn't provide the unchecked
keyword. But it appears to be unnecessary in this statement:
const int dwAccess = unchecked((int)0xC0000000);
I have two observations here:
dwAccess
is declared as a constantSystem.Int32
Given these, will it be safe to just go with this:
Const dwAccess As Integer = &HC0000000
It's being used in this context:
[DllImport("Kernel32", CharSet = CharSet.Auto, SetLastError = true)]
private static extern SafeFileHandle CreateFile(string lpFileName, int dwAccess, int dwShareMode,
IntPtr securityAttrs, int dwCreationDisposition,
int dwFlagsAndAttributes, IntPtr hTemplateFile);
Clarification: This question is not about whether the unchecked
keyword is necessary in C#. Clearly it is. It's about whether the absence of the keyword in VB.NET precludes successful conversion of the statement.
The answer is a yes. It's redundant and can be removed.
The unchecked keyword is used to suppress overflow-checking for integral-type arithmetic operations and conversions.
Update, this answer should have been qualified.
If the original VB.NET code was unchecked then the equivalent C# code would function as is unchecked as well in the same way. Both will overflow and both will give the same results.