Can IntPrt used in conditional statements ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

Can i use IntPtr in conditional statements like if/else?

Example

IntPtr a = (IntPtr)123;

if (a < 125)
{
// call this
}

Any help? I keep getting an error.

Thanks.
 
Both 'a' and '125' are incompatible types, you have to convert the IntPtr
back to an int.

if((int)a < 125)

Note that you can't apply the < operator to IntPtr types, so:
if(a < (IntPtr)125)

won't work either.

Willy.
 
Hi Chua
You explicitly need to cast the IntPtr to integer in order to compare it
to the Int value

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Thanks Willy and Mohamoss.

So casting IntPtr to int, does not lose any data. Am i right?

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top