码迷,mamicode.com
首页 > Windows程序 > 详细

C#中使用Buffer.BlockCopy()方法将string转换为byte array的方法:

时间:2016-07-20 21:07:35      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:


 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; }

 

C#中使用Buffer.BlockCopy()方法将string转换为byte array的方法:

标签:

原文地址:http://www.cnblogs.com/ChineseMoonGod/p/5689526.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!