开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 5246|回复: 3
收起左侧

[C#源码] E语言中字节集·对应C#代码

[复制链接]
结帖率:100% (1/1)
发表于 2022-12-19 08:45:01 | 显示全部楼层 |阅读模式   云南省楚雄彝族自治州
In E language, a "byteset" is a data type that represents a set of bytes, similar to an array of bytes in C#. Here is how you might declare and use a byteset in E language:

byteset bs;
bs = "Hello, world!";
bs[0] = 'H'; // Set the first byte of the byteset to 'H'
bs[5] = ','; // Set the sixth byte of the byteset to ','
print(bs); // Prints "Hello, world!"

To achieve a similar effect in C#, you can use a byte array:


byte[] bs = Encoding.UTF8.GetBytes("Hello, world!");bs[0] = (byte)'H'; // Set the first byte of the array to 'H'bs[5] = (byte)','; // Set the sixth byte of the array to ','Console.WriteLine(Encoding.UTF8.GetString(bs)); // Prints "Hello, world!"


You can also use a MemoryStream object to manipulate a sequence of bytes as a stream in C#:


using (MemoryStream stream = new MemoryStream())
{
    stream.WriteByte((byte)'H'); // Write the byte 'H' to the stream
    stream.WriteByte((byte)','); // Write the byte ',' to the stream
    stream.Write(Encoding.UTF8.GetBytes("ello, world!"), 0, 12); // Write the remaining bytes to the stream
    stream.Position = 0; // Reset the position of the stream to the beginning
    Console.WriteLine(new StreamReader(stream).ReadToEnd()); // Prints "Hello, world!"
}


Keep in mind that the specific syntax and behavior of bytesets in E language may vary depending on the implementation you are using. Make sure to consult the documentation for your specific E language implementation for more information.










结帖率:60% (3/5)
发表于 2022-12-25 01:11:09 | 显示全部楼层   湖南省益阳市
2467201838dark 发表于 2022-12-25 01:10
直接(Array)object.Cast(byte).ToArray(); 就能直接传字节集

(obj as Array).Cast<byte>().ToArray();
回复 支持 反对

使用道具 举报

结帖率:60% (3/5)
发表于 2022-12-25 01:10:43 | 显示全部楼层   湖南省益阳市
直接(Array)object.Cast(byte).ToArray(); 就能直接传字节集
回复 支持 反对

使用道具 举报

结帖率:100% (9/9)
发表于 2022-12-19 12:37:16 | 显示全部楼层   重庆市重庆市
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表