unsigned char指针在C#中? [英] unsigned char pointer in C#?

查看:160
本文介绍了unsigned char指针在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将一些代码从C ++转换到C#的过程中,我发现了这一点:

In the middle of translating some code from C++ to C#, I found this,

unsigned char *p = m_pRecvBuffer + 5;
unsigned int noncelen1 = *p * 256 + p[1];

如何将它转换为C#? m_pRecvBuffer 是一个字符数组,但是我将其存储为字节数组。

How do I translate this into C#? m_pRecvBuffer is a char-array, however I store it as a byte-array.

推荐答案

类似于

byte[] p = new byte[m_pRecvBuffer.Length - 5];
Array.Copy(m_precvBuffer, p, m_pRecvBuffer.Length - 5);
uint noncelen1 = p[0] * 256 + p[1];

但在这种情况下,我不认为你真的需要使用数组副本。只需使用

But in that case I don't think you actually need to use an array copy. Just using

uint noncelen1 = p[5] * 256 + p[6];

应该已经足够了。

这篇关于unsigned char指针在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆