本文整理匯總了C#中System.IO.StringReader.Lines方法的典型用法代碼示例。如果您正苦於以下問題:C# StringReader.Lines方法的具體用法?C# StringReader.Lines怎麽用?C# StringReader.Lines使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.StringReader
的用法示例。
在下文中一共展示了StringReader.Lines方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Lines_OptionsInvalid
public void Lines_OptionsInvalid()
{
TextReader s = new StringReader ("");
s.Lines ((TextReaderCodaOptions) (-1));
}
示例2: Lines
/// <summary>
/// Enumerates the lines of text inside the string.
/// </summary>
///
/// <param name="input">
/// The string to process on a line-by-line basis.
/// </param>
///
/// <returns>
/// An enumeration of the lines contained in <paramref name="input"/>.
/// </returns>
public static IEnumerable<string> Lines(this string input)
{
using (var sr = new StringReader(input))
{
foreach (var line in sr.Lines())
{
yield return line;
}
}
}
示例3: lines
public void lines()
{
Assert.Throws<ArgumentNullException>(() => StreamExtensions.Lines(null));
using (var reader = new StringReader(string.Empty))
{
Assert.False(reader.Lines().Any());
Assert.Equal(-1, reader.Read());
}
using (var reader = new StringReader(string.Empty))
{
Assert.False(reader.Lines(true).Any());
Assert.Throws<ObjectDisposedException>(() => reader.Read());
}
using (var reader = new StringReader($"First{Environment.NewLine}Second{Environment.NewLine}"))
{
var lines = reader.Lines();
Assert.Equal(3, lines.Count());
Assert.Equal("First", lines[0]);
Assert.Equal("Second", lines[1]);
Assert.Equal(string.Empty, lines[2]);
Assert.False(reader.Lines().Any());
Assert.Equal(-1, reader.Read());
}
}