Conversion to byte

  • Thread starter Thread starter Robert Scheer
  • Start date Start date
R

Robert Scheer

Hi.

I am trying to add a value to a byte property as below:

Utilization.Limit +=1

This gives me a message saying that Option Strict On disallows
implicit conversions from 'Integer' to 'Byte'.

I changed my code to:

Utilization.Limit += Convert.ToByte(1)

And now it is working. But is this correct? Or is there a better way
to increment my Byte property?

Regards,
Robert Scheer
 
Am 05.07.2010 18:28, schrieb Robert Scheer:
Hi.

I am trying to add a value to a byte property as below:

Utilization.Limit +=1

This gives me a message saying that Option Strict On disallows
implicit conversions from 'Integer' to 'Byte'.

I changed my code to:

Utilization.Limit += Convert.ToByte(1)

And now it is working. But is this correct? Or is there a better way
to increment my Byte property?

Utilization.Limit += CByte(1)

As CByte is a keyword, not a function, the value is compiled as
a byte, not converted at runtime. Though, your version is ok, too.
 
Am 05.07.2010 22:15, schrieb Onur Güzel:
Yep, but CByte is mentioned as "function" on MSDN which you call it as
keyword:

http://msdn.microsoft.com/en-us/library/2ssb79wt(VS.85).aspx

VBScript documentation? :-)

Well, it's used like a function but what the compiler does
depends on the type of the expression. It's not necessarily
a function call.
Acturally Cxxx (and CByte) is conversion operator.

Or "conversion function": ;-)
http://msdn.microsoft.com/en-us/library/s2dy91zy.aspx
 
Back
Top