WowSki Bowse
WowSki Bowse

Reputation: 25

IntPtr to Int - C#

I have this code :

public uint StringsSize { get; set; }
byte[] buffer = new byte[(IntPtr) XSC.header.StringsSize];

returning the following error :

"Cannot explicitly convert type 'intptr' to 'int'. An explicit conversion exists (are you missing a cast?)"

Any real guidance on fixing this would be appreciated, it's troubled me on several occasions with this tool .. Also, I apologize if this is a duplicated question, I was unable to find a simple fix/solution after several Google searches.

Upvotes: 1

Views: 5197

Answers (2)

Jöcker
Jöcker

Reputation: 6758

You can try like this:

int numInt = intPtrVar.ToInt32();

Upvotes: 0

Allan Elder
Allan Elder

Reputation: 4104

Convert the IntPtr to the int type like so:

var buffer = new byte[((IntPtr) XSC.header.StringsSize).ToInt64()];

Upvotes: 4

Related Questions