PC Review


Reply
Thread Tools Rate Thread

Conversion to byte

 
 
Robert Scheer
Guest
Posts: n/a
 
      5th Jul 2010
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
 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      5th Jul 2010
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.


--
Armin
 
Reply With Quote
 
Onur Güzel
Guest
Posts: n/a
 
      5th Jul 2010
On Jul 5, 8:26*pm, Armin Zingler <az.nos...@freenet.de> wrote:
> 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.
>
> --
> Armin


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

Acturally Cxxx (and CByte) is conversion operator.

Onur Güzel
 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      5th Jul 2010
Am 05.07.2010 22:15, schrieb Onur Güzel:
>> 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.
>>

> 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


--
Armin
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Byte[] Conversion shapper Microsoft C# .NET 15 6th Oct 2009 09:36 PM
Marshall::Copy and BYTE* and byte[] conversion? BartMan Microsoft VC .NET 2 29th Oct 2008 06:18 PM
byte conversion Lew Barnesson Microsoft C# .NET 4 18th Dec 2006 10:01 PM
Byte to int Conversion ..?? Sanjay Microsoft VB .NET 4 18th Apr 2006 06:46 PM
Re: C# byte[] conversion to XML Nicholas Paldino [.NET/C# MVP] Microsoft C# .NET 2 17th Aug 2004 03:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:11 AM.