Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Confusing Array or Byte ?? Syntax

Can one of you fine C# experts decipher this for me?

new[] {(byte) (0x80 | byteArray.Length)}

I found this in same sample code, but have no idea what it is doing.
If someone could explain and/or re-write it in VB or Powershell that would be awesome.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have googled for hours but my google-foo seems to be a little weak on this one.

For anyone that simply cannot get past the fact that this is ‘incomplete’ perhaps this snippet would suit you better…

new[] {(byte) (0x80 | 2 )}

>Solution :

This is an array initializer syntax in C#. You can check this question for all syntaxes. I infer that this is assigned to a variable of type byte[] – but your code is incomplete, so I can only make assumptions here.

In addition, the initializer explicitly adds the value of expression (byte) (0x80 | byteArray.Length) in the array. This is a bitwise OR operation between
0x80 in hex (128 in Decimal) and the length of the byteArray variable.

I do not know the purpose you are using this, but this it what it does in two sentences.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading