C# Stream 轉 Bytes

        #region - Stream 轉 Bytes -
        /// <summary>
        /// Stream 轉 Bytes
        /// </summary>
        /// <param name="stream"> Stream</param>
        /// <returns> Bytes</returns>
        public static byte[] StreamToBytes( Stream stream)
        {
            byte[] bytes = new byte[stream.Length];
            stream.Read(bytes, 0, bytes.Length);
            stream.Seek(0, SeekOrigin.Begin);
            return bytes;
        }
        #endregion
       
        #region - Bytes 轉 Stream -
        /// <summary>
        /// Bytes 轉 Stream
        /// </summary>
        /// <param name="bytes"> Bytes</param>
        /// <returns> Stream</returns>
        public static Stream BytesToStream( byte[] bytes)
        {
            return new MemoryStream(bytes);
        }
        #endregion

留言

這個網誌中的熱門文章

C# 在 GDI+ 中發生泛型錯誤

[LeetCode] Robot Return to Origin