Ridvan
Ridvan

Reputation: 11

Convert pointer to loop option in C#

How would I convert this into a loop and not to use the pointer.

byte[] InputBuffer = new byte[8];
unsafe {
      fixed (byte* pInputBuffer = InputBuffer) {
         ((long*)pInputBuffer)[0] = value;
      }
}

I am trying to use the code from this page: query string parameter obfuscation

Upvotes: 1

Views: 349

Answers (1)

Ben Voigt
Ben Voigt

Reputation: 283793

There's no looping here. You could use BitConverter.GetBytes instead of the unsafe type-punning cast.

byte[] InputBuffer = BitConverter.GetBytes(value);

replaces all six original lines of code.

Upvotes: 3

Related Questions