加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 在我的WPF应用程序中无法使用Array.Copy()

发布时间:2020-12-15 08:49:01 所属栏目:百科 来源:网络整理
导读:我是一名C开发人员,最近开始从事 WPF工作.好吧,我在我的应用程序中使用Array.Copy(),看起来我无法完全获得所需的结果. 我在我的C应用程序中完成了如下操作: static const signed char version[40] = {'A','U','D','I','E','N','C',// name 0,// reserved,fi
我是一名C开发人员,最近开始从事 WPF工作.好吧,我在我的应用程序中使用Array.Copy(),看起来我无法完全获得所需的结果.

我在我的C应用程序中完成了如下操作:

static const signed char version[40] = {
'A','U','D','I','E','N','C',// name
 0,// reserved,firmware size
 0,// board number
 0,// variant,version,serial
 0,0     // date code,reserved
};

unsigned char sendBuf[256] = {};
int memloc = 0;
sendBuf[memloc++] = 0;
sendBuf[memloc++] = 0;

// fill in the audience header
memcpy(sendBuf+memloc,8); // the first 8 bytes
memloc += 16; // the 8 copied,plus 8 reserved bytes

我在我的WPF(C#)应用程序中执行了类似的操作,如下所示:

Byte[] sendBuf = new Byte[256];

char[] version = 
        {
                'A',// name
                '0','0',firmware size
                '0',// board number
                '0',serial
                '0','0'          // date code,reserved
        };

// fill in the address to write to -- 0
        sendBuf[memloc++] = 0;
        sendBuf[memloc++] = 0;

        // fill in the audience header
        Array.Copy(sendBuf + memloc,8);   // the first 8 bytes
        memloc += 16;

但是它在Array.Copy中抛出了一个错误(sendBuf memloc,8);因为运算符”不能应用于’byte []’和’int’类型的操作数.

怎么能实现这个???? :) 请帮忙 :)

解决方法

for(int i = 0; i < 8; i++)
{
    sendBuf[i+memloc] = Convert.ToSByte(version[i]);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读