转换的指针在C#循环选项指针、选项

2023-09-03 07:21:40 作者:青春无限坑i

我将如何转换这种成一个圈,而不是使用指针。

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;
      }
}

我想用code从该页面:查询字符串参数迷惑

推荐答案

这里有没有循环。您可以使用 BitConverter.GetBytes 而不是不安全类型夯实投。

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

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

替换所有六个原线code。

replaces all six original lines of code.