I have a byte[] array of one size, and I would like to truncate it into a smaller array?
I just want to chop the end off.
Most likely the '?' is the ternary operator. Its grammar is: RESULT = (COND) ? ( STATEMEN IF TRUE) : (STATEMENT IF FALSE) It is a nice shorthand for the typical if-else statement: if (COND) { RESULT = (STATEMENT IF TRUE); } else { RESULT = (STATEMENT IF FALSE);
|= just assigns the bitwise OR of a variable with another to the one on the LHS.
C operators are one of the features in C which has symbols that can be used to perform mathematical, relational, bitwise, conditional, or logical manipulations. The C programming language has a lot of built-in operators to perform various tasks as per the need of the program.
Arrays are fixed-size in C# (.NET).
You'll have to copy the contents to a new one.
byte[] sourceArray = ... byte[] truncArray = new byte[10]; Array.Copy(sourceArray , truncArray , truncArray.Length);
You could use Array.Resize
, but all this really does is make a truncated copy of the original array and then replaces the original array with the new one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With