class1.cs
来自「C#开发教程 由浅入深 配有实例 是初学者的好帮手」· CS 代码 · 共 59 行
CS
59 行
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 + =
减小字号Ctrl + -
显示快捷键?