<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 如何:將字節數組轉換為 int(C# 編程指南) 此示例演示如何使用 [BitConverter](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.aspx) 類將字節數組轉換為 [int](https://msdn.microsoft.com/zh-cn/library/5kzh1b5w.aspx) 并返回字節數組。例如,在從網絡讀取字節之后,可能需要將字節轉換為內置數據類型。除了示例中的 [ToInt32(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.toint32.aspx) 方法之外,下表列出了 [BitConverter](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.aspx) 類中將字節(來自字節數組)轉換為其他內置類型的方法。 | 返回類型 | 方法 | | --- | --- | | **bool** | [ToBoolean(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.toboolean.aspx) | | **char** | [ToChar(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.tochar.aspx) | | **double** | [ToDouble(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.todouble.aspx) | | **short** | [ToInt16(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.toint16.aspx) | | **int** | [ToInt32(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.toint32.aspx) | | **long** | [ToInt64(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.toint64.aspx) | | **float** | [ToSingle(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.tosingle.aspx) | | **ushort** | [ToUInt16(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.touint16.aspx) | | **uint** | [ToUInt32(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.touint32.aspx) | | **ulong** | [ToUInt64(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.touint64.aspx) | 此示例實例化字節數組,并在計算機結構為 little-endian 的情況下反轉數組(即首先存儲最低有效字節),然后調用 [ToInt32(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.toint32.aspx) 方法以將數組中的四個字節轉換為 **int**。 [ToInt32(Byte[], Int32)](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.toint32.aspx) 的第二個參數指定字節數組的起始索引。 | ![](https://box.kancloud.cn/2016-01-31_56adb62c1380a.jpg) 注意 | | :-- | | 輸出可能會根據計算機結構的 endian 設置而不同。 | ``` byte[] bytes = { 0, 0, 0, 25 }; // If the system architecture is little-endian (that is, little end first), // reverse the byte array. if (BitConverter.IsLittleEndian) Array.Reverse(bytes); int i = BitConverter.ToInt32(bytes, 0); Console.WriteLine("int: {0}", i); // Output: int: 25 ``` 在此示例中,調用 [BitConverter](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.aspx) 類的 [GetBytes(Int32)](https://msdn.microsoft.com/zh-cn/library/de8fssa4.aspx) 方法以將 **int** 轉換為字節數組。 | ![](https://box.kancloud.cn/2016-01-31_56adb62c1380a.jpg) 注意 | | :-- | | 輸出可能會根據計算機結構的 endian 設置而不同。 | ``` byte[] bytes = BitConverter.GetBytes(201805978); Console.WriteLine("byte array: " + BitConverter.ToString(bytes)); // Output: byte array: 9A-50-07-0C ``` ## 請參閱 [BitConverter](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.aspx) [IsLittleEndian](https://msdn.microsoft.com/zh-cn/library/system.bitconverter.islittleendian.aspx) [類型(C# 編程指南)](https://msdn.microsoft.com/zh-cn/library/ms173104.aspx)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看