⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 C#开发教程 由浅入深 配有实例 是初学者的好帮手
💻 CS
字号:
using System;
using System.IO;

namespace MemStream
{
    class MemStreamApp
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Write some data to a MemoryStream
            MemoryStream m = new MemoryStream(64);
            Console.WriteLine(
                "Length: {0}\tPosition: {1}\tCapacity: {2}",
                m.Length, m.Position, m.Capacity);

            for (int i = 0; i < 64; i++)
            {
                m.WriteByte((byte)i);
            }
            Console.WriteLine(
                "Length: {0}\tPosition: {1}\tCapacity: {2}",
                m.Length, m.Position, m.Capacity);

            // Read it back again
            Console.WriteLine("\nContents:");
            byte[] ba = m.GetBuffer();
            foreach (byte b in ba)
            {
                Console.Write("{0,-3}", b);
            }

            // Write some more, exceeding capacity
            string s = "Foo";
            for (int i = 0; i < 3; i++)
            {
                m.WriteByte((byte)s[i]);
            }
            Console.WriteLine(
                "\nLength: {0}\tPosition: {1}\tCapacity: {2}",
                m.Length, m.Position, m.Capacity);

            for (int i = 0; i < (256-67)+1; i++)
            {
                m.WriteByte((byte)i);
            }
            Console.WriteLine(
                "\nLength: {0}\tPosition: {1}\tCapacity: {2}",
                m.Length, m.Position, m.Capacity);

            // Associate the MemoryStream with a File
            FileStream fs = new FileStream("Goo.txt",
                FileMode.Create, FileAccess.Write);
            m.WriteTo(fs);
            m.Close();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -