Convert pointer to loop option in C#

て烟熏妆下的殇ゞ 提交于 2019-12-31 03:49:06

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/4882378/convert-pointer-to-loop-option-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!