Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a console application. I would like to use uint for the exit code, eg. Environment.Exitcode = 0x80070005

 

Is there a method for returning unsigned integers or long integers? The reason is, I'm catching exceptions and want to return the native windows error code, such as System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Posted

0x80070005 = 2,147,942,405.

 

Int.MaxValule returns: 2,147,483,647

 

As you can see, if I were to convert it to an Int, it would truncate the numbers, as MaxValue is 458,758 lower than my number.

Posted

PlausiblyDamp said cast not convert.

I.e.

uint x = 2147942405;

int y = (int)x;

Console.WriteLine("x:"+x.ToString());

Console.WriteLine("y:"+y.ToString());

which results in:

x:2147942405

y:-2147024891

 

Hope that helps,

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...