本文整理汇总了C#中System.IO.StringReader类的典型用法代码示例。如果您正苦于以下问题:C# StringReader类的具体用法?C# StringReader怎么用?C# StringReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringReader类属于System.IO命名空间,在下文中一共展示了StringReader类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
ReadCharacters();
}
static async void ReadCharacters()
{
StringBuilder stringToRead = new StringBuilder();
stringToRead.AppendLine("Characters in 1st line to read");
stringToRead.AppendLine("and 2nd line");
stringToRead.AppendLine("and the end");
using (StringReader reader = new StringReader(stringToRead.ToString()))
{
string readText = await reader.ReadToEndAsync();
Console.WriteLine(readText);
}
}
}
}
输出:
Characters in 1st line to read and 2nd line and the end
示例2: new StringReader(String value)
//引入命名空间
using System;
using System.IO;
class MainClass
{
public static void Main()
{
Object someObject = new StringReader("This is a StringReader");
if (IsType(someObject, "System.IO.TextReader"))
{
Console.WriteLine("GetType: someObject is a TextReader");
}
}
public static bool IsType(object obj, string type)
{
Type t = Type.GetType(type, true, true);
return t == obj.GetType() || obj.GetType().IsSubclassOf(t);
}
}