Notifications
Clear all

[Closed] System.Byte setvalue question?

Hello,
I have a very simple question,how can I set value to a byte?In this case,I want to set number 888 to a byte,unfortunately,it gets an error,how shall I fix it?

byte_data=dotnetobject "System.Byte[]" 1
byte_data.length
--1
byte_data.GetValue 0
--0
byte_data.SetValue 888 0
-- Runtime error: dotNet runtime exception: Cannot widen from source type to target type either because the source type is a not a primitive type or the conversion cannot be accomplished.
2 Replies

Byte max value is 2^8-1 which is 255. So there’s not enough bits to represent the value you’re trying to set.

byte_data.Set index 127
byte_data.Get index

Works like you said,many thanks !