为什么C#.NET以字节数组的格式从NetworkStream读取或写入数据 [英] Why C# .NET reads or writes data from the NetworkStream in format of byte array

查看:341
本文介绍了为什么C#.NET以字节数组的格式从NetworkStream读取或写入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..我有兴趣在C#.net中使用字节数组,为什么.Net使用这种数组来存储,保存和传输数据,特别是在通过网络传输数据的情况下,例如Read()方法在NetworkStream类中:



hi.. I'm interested in using byte array in C# .net, and why .Net use this sort of array to store , save and transfer data specially in case of transferring data through network,for example Read() method in NetworkStream class :

NetworkStream clientStream = tcpClient.GetStream();
byte[] message = new byte[4096];
clientStream.Read(message, 0, 4096);

推荐答案

我参与了一个通过网络传输数据的类似项目。 UI过程在.NET中,我们使用适配器(在C ++ / CLI中)将数据(原始和用户定义)转换为二进制数组,因为低级网络API期望数据以字节数组的形式。此外,我们必须将较大的数据分解为块并将其转换为字节数组。因此,在传输之前,我们或多或少地将数据类型更改为字节数组。
I have worked on a similar project of transmitting data via network. The UI process was in .NET, we used an adapter (in C++/CLI) for converting data (both primitive and user defined) to binary array because the low level network API's expected the data in terms of byte array. Also we have to break down the larger data into chunks and transfer the same as byte array. Hence it was more or less a constraint for us to change the data types to byte array before transmitting.


我们不做你的功课:设置是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!


这篇关于为什么C#.NET以字节数组的格式从NetworkStream读取或写入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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