登录
首页 » C#源码 » C# 写入并读取内存流

C# 写入并读取内存流

于 2022-03-11 发布 文件大小:12.92 kB
0 161
下载积分: 2 下载次数: 1

代码说明:

C# 写入并读取内存流,演示一些基本的内存流操作方法,编写以下代码可实现这些功能:   byte[] BContent = Encoding.Default.GetBytes(textBox1.Text);   MemoryStream MStream = new MemoryStream(100);   MStream.Write(BContent, 0, BContent.Length);   richTextBox1.Text = "分配给该流的字节数:" + MStream.Capacity.ToString() + " 流长度:"    + MStream.Length.ToString() + " 流的当前位置:" + MStream.Position.ToString();   MStream.Seek(0, SeekOrigin.Begin);   byte[] byteArray = new byte[MStream.Length];   int count = MStream.Read(byteArray,0,(int)MStream.Length-1);   while (count < MStream.Length)   {    byteArray[count++] = Convert.ToByte(MStream.ReadByte());   }   char[] charArray = new char[Encoding.Default.GetCharCount(byteArray, 0, count)];   Encoding.Default.GetChars(byteArray, 0, count, charArray, 0);   for (int i = 0; i < charArray.Length; i++)   {    richTextBox2.Text += charArray[i].ToString();   }

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • C#获取时区并把北京时间转换为目标时区时间
    C# 获取计算机上存在的时区信息,并把北京时间转换为目标时区时间。
    2022-03-26 01:29:39下载
    积分:1
  • C# IrisSkin2.dll实现漂亮的窗口 并显示加载的Loading动画
    C# IrisSkin2.dll实现漂亮的窗口 并显示加载的Loading动画 ,读取数据的时候显示Loading,制作一个窗体的操作等待功能,用来演示Loading效果的窗口也是相当漂亮哦,不过这个窗口的实现是使用了一个第三方的组件: IrisSkin2.dll,使用时请确保在Debug目录下。使用了WaitingBox插件。   窗口中的按钮风格圆滑,单击后会出现Loading动画效果,窗口中同时显示"正在处理数据,请稍后...";如示例图所示的效果。
    2022-02-26 00:39:03下载
    积分:1
  • C#读取数据库内容并在dataGridView中显示
    C#从数据库中读取内容并显示在dataGridView中,这似乎是一个很实用的功能,在数据库应用的时候,我们都要通过dataGridView来显示数据,这个例子可帮助初学者很好的掌握此功能的具体实现,一些代码片段分享如下:   private void button1_Click(object sender, EventArgs e)   {    //实例化SqlConnection变量conn,连接数据库    conn = new SqlConnection("server=.;database=db_15;uid=sa;pwd=");    //实例化SqlDataAdapter对象    SqlDataAdapter sda = new SqlDataAdapter("select * from tb_emp", conn);    DataSet ds = new DataSet(); //实例化DataSet对象    sda.Fill(ds);//使用SqlDataAdapter对象的Fill方法填充DataSet    dataGridView1.DataSource = ds.Tables[0];//设置dataGridView1控件的数据源    dataGridView1.RowHeadersVisible = false;//禁止显示行标题    //使用for循环设置控件的列宽    for (int i = 0; i < dataGridView1.ColumnCount; i++)    {    dataGridView1.Columns[i].Width = 84;    }    button1.Enabled = false;//禁用按钮    dataGridView1.Columns[0].ReadOnly = true;//将控件设置为只读   }   private DataTable dbconn(string strSql)//建立一个DataTable类型的方法   {    this.adapter = new SqlDataAdapter(strSql, conn);//实例化SqlDataAdapter对
    2022-07-24 21:44:03下载
    积分:1
  • C# 中文简体繁体转换小程序
    Visual C# 简繁体转换,实现中文汉字的简体繁体转换功能,相信这个C#小程序源码会很实用吧,经常用到。编译运行后,请输入要转换的文字,单击对应的按钮,即可实现转换功能,绑定在对应按钮上的代码如下:   C#中文繁体转简体源码:   private void button1_Click(object sender, EventArgs e)   {    string src = txtSrcText.Text.Trim();    byte[] srcByte = Encoding.Default.GetBytes(src);    byte[] desByte = new byte[srcByte.Length];    LCMapString(2052, LCMAP_SIMPLIFIED_CHINESE, srcByte, -1, desByte, srcByte.Length);    string des = Encoding.Default.GetString(desByte);    txtDesText.Text = des;   }   C#中文简体转繁体源码:   private void button2_Click(object sender, EventArgs e)   {    string src = txtSrcText.Text.Trim();    byte[] srcByte = Encoding.Default.GetBytes(src);    byte[] desByte = new byte[srcByte.Length];    LCMapString(2052, LCMAP_TRADITIONAL_CHINESE, srcByte, -1, desByte, srcByte.Length);    string des = Encoding.Default.GetString(desByte);    txtDesText.Text = des;   }
    2022-03-12 07:23:03下载
    积分:1
  • Visual C# LINQ转换为一对多字典
    Visual C# 转换为一对多字典,构造泛型列表,使用LINQ查找用户代码小于3的列表,此时的query变量的类型是IEnumerable类型,使用ToLookup方法将query转换为一对多字典类型:   ILookup userLookup = query.ToLookup(itm => itm.UserCode);   label1.Text = "ILookup的结果是: ";   foreach (var user in userLookup)//遍历查询结果   {    label1.Text += user.Key;//显示主键    label1.Text += " ";    foreach (var user2 in user)//遍历所有值    {    label1.Text += user2.UserName + " , ";//显示键值    }    label1.Text += " ";   }
    2023-05-18 03:20:03下载
    积分:1
  • 7Zip
    This file is part of SevenZipSharp.    SevenZipSharp is free software: you can redistribute it and/or modify    it under the terms of the GNU Lesser General Public License as published by    the Free Software Foundation, either version 3 of the License, or    (at your option) any later version.    SevenZipSharp is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public License    along with SevenZipSharp.  If not, see .
    2022-07-20 00:09:31下载
    积分:1
  • C# Access版资产管理系统
    C# Access版资产管理系统源代码,SQL数据库版,数据库初始用户名为sa,密码为sa;本程序在界面方面使用IrisSkin2.dll进行了美化。关于数据库配置的说明:正常情况下本软件不需要人工配置,程序会自动配置运行环境。如果自动配置失败,有如下方法配置:   1.在C目录下建立名为Solut_EquipentMgr_Dat的文件夹,并把本软件根目录下的Data文件夹下Equipment_Manage_dat.mdf 、 Equipment_Manage_log.ldf、BuidDatabase.sql、KillProcessProcedure.sql 四个文件复制到该文件夹内。   2.打开SQL Server 2005 附加Equipment_Manage数据库。   3.在运行Data目录下KillProcess.bat文件即可。
    2022-02-06 04:12:23下载
    积分:1
  • TMS320C6748各个接口外设所有标准程序 (亲测好使)
    TMS320C6748各个接口外设所有标准源码程序  (亲测好使)
    2022-07-16 14:39:18下载
    积分:1
  • C# 在LINQ to DataSet中对分组操作执行子查询
    C# 在LINQ to DataSet中对分组操作执行子查询,相关代码:   private void button1_Click(object sender, EventArgs e)   {//在LINQ to DataSet中对分组操作执行子查询    SqlConnection MyConnection = new SqlConnection();    MyConnection.ConnectionString = @"Data Source =.SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";    MyConnection.Open();    SqlCommand MyCommand = new SqlCommand("Select * From Orders ", MyConnection);    DataSet MySet = new DataSet();    SqlDataAdapter MyAdapter = new SqlDataAdapter(MyCommand);    MyAdapter.Fill(MySet);    DataTable MyQueryTable = MySet.Tables[0];    var MyQuery = from MyOrder in MyQueryTable.AsEnumerable()    orderby MyOrder.Field("ShipCity")    group MyOrder by MyOrder.Field("ShipCity") into g    select new    {    MyCity = g.Key,    MyMaxFreight = (from MyData in g select MyData.Field("Freight")).Max()   
    2022-01-27 20:20:32下载
    积分:1
  • LED显示屏控制卡
    T45DB041B的模拟SPI程序,验证过无问题! /********************************************************************************* * 函数原型:unsigned char SPI_ReadByte(void);                      * 名    称:SPI_ReadByte * 功    能:从AT45DB041B通过SPI_SO口读入1BYTE数据 * 入口参数:无 * 出口参数:返回读入的1BYTE数据 **********************************************************************************/ unsigned char SPI_ReadByte(void) {     unsigned char i,rByte=0;     for(i=0;i
    2022-03-25 18:35:36下载
    积分:1
  • 696516资源总数
  • 106658会员总数
  • 16今日下载