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

📄 class1.cs

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

namespace StringReadWrite
{
    class StringReadWriteApp
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Using StringWriter
            StringWriter w = new StringWriter();
            w.WriteLine("Sing a song of {0} pence", 6);
            string s = "A pocket full of rye";
            w.Write(s);
            w.Write(w.NewLine);
            w.Write(
                String.Format(4 +" and " +20 +" blackbirds"));
            w.Write(new StringBuilder(" baked in a pie"));
            w.WriteLine();
            Console.WriteLine(w);

            // Using the internal StringBuilder
            StringBuilder sb = w.GetStringBuilder();
            int i = sb.Length;
            sb.Append("The birds began to sing");
            sb.Insert(i, "When the pie was opened\n");
            sb.AppendFormat(
                "\nWasn't that a {0} to set before the King",
                "dainty dish");
            Console.WriteLine(w);

            // Using StringReader
            Console.WriteLine();
            StringReader r = new StringReader(w.ToString());
            string t = r.ReadLine();
            Console.WriteLine(t);
            Console.Write((char)r.Read());
            char[] ca = new char[37];
            r.Read(ca, 0, 19);
            Console.Write(ca);
            r.ReadBlock(ca, 0, 37);
            Console.Write(ca);
            Console.WriteLine(r.ReadToEnd());

            r.Close();
            w.Close();
        }
    }
}

⌨️ 快捷键说明

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