Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何读取字节数组中的前3个字节_C# - Fatal编程技术网

C# 如何读取字节数组中的前3个字节

C# 如何读取字节数组中的前3个字节,c#,C#,我有字节数组,我只需要读取前3个字节,不需要更多 C#4.0怎么样 Byte byte1 = bytesInput[0]; Byte byte2 = bytesInput[1]; Byte byte3 = bytesInput[2]; 或在数组中: Byte[] threeBytes = new Byte[] { bytesInput[0], bytesInput[1], bytesInput[2] }; 或: 这些够了吗 IEnumerable<byte> firstThree

我有字节数组,我只需要读取前3个字节,不需要更多

C#4.0怎么样

Byte byte1 = bytesInput[0];
Byte byte2 = bytesInput[1];
Byte byte3 = bytesInput[2];
或在数组中:

Byte[] threeBytes = new Byte[] { bytesInput[0], bytesInput[1], bytesInput[2] };
或:

这些够了吗

IEnumerable<byte> firstThree = myArray.Take(3);
byte[] firstThreeAsArray = myArray.Take(3).ToArray();
List<byte> firstThreeAsList = myArray.Take(3).ToList();
IEnumerable firstThree=myArray.Take(3);
字节[]firstThreeAsArray=myArray.Take(3.ToArray();
List firstThreeAsList=myArray.Take(3.ToList();

简单for循环也可以完成这项工作

for(int i = 0; i < 3; i++) 
{
   // your logic
}

数组是从0索引的,因此前3个字节位于数组的0、1和2插槽中。

这是一个家庭作业,不是吗?
for(int i = 0; i < 3; i++) 
{
   // your logic
}
byte first = byteArr[0];
byte second = byteArr[1];
byte third = byteArr[2];
byte b1 = bytearray[0];
byte b2 = bytearray[1];
byte b3 = bytearray[2];