public static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count);
將指定數目的字節從起始於特定偏移量的源數組復制到起始於特定偏移量的目標數組。
/// <summary> /// C#中使用Buffer.BlockCopy()方法將string轉換為byte array的方法 /// </summary> /// <param name="str"></param> /// <returns></returns> static byte[] GetBytes(string str) { byte[] bytes = new byte[str.Length * sizeof(char)]; Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); return bytes; }