C# char[] 转换为 byte[]

 时间:2026-02-12 14:44:38

1、新建一个控制台项目

C# char[] 转换为 byte[]

2、写主函数

 static void Main(string[] args)        {            string c="";            c = Console.ReadLine();            char[] p = c.ToCharArray();            byte[] pb = new byte[64];            List<byte> ls= new List<byte>();            alloc(ls, p,64);            FileStream fs = new FileStream("D:\\abc.txt", FileMode.OpenOrCreate);            BinaryWriter sw = new BinaryWriter(fs);            sw.Write(ls.ToArray());            sw.Close();            fs.Close();

}

3、写alloc

 public static int  alloc(List<byte> bytes,char []p,int block)         {            for (int i=0;i<p.Length ;i++ )            {                bytes.Add((byte)p[i]);            }                        while (bytes.Count % block != 0)             {                bytes.Add(0);            }            return bytes.Count/block;        }

4、运行测试一下

C# char[] 转换为 byte[]

5、打开txt

C# char[] 转换为 byte[]

  • C#判断当前系统日期是星期几
  • vs2015如何附加进程调试
  • sql语句怎么查出所有数组中的值呢
  • 如何判断二维数组里是否有某个值
  • 禁用远程登录此电脑桌面 禁止Telnet登录设置
  • 热门搜索
    ps如何安装字体 经营方式怎么填 手机速度慢怎么解决 完美生活许巍 3月18日是什么星座 嘉兴到乌镇怎么坐车 麻将记号1一9怎么做 word段落间距怎么调 性激素六项是什么 箭头符号怎么打