本文整理汇总了C#中System.IO.TextWriter.Where方法的典型用法代码示例。如果您正苦于以下问题:C# TextWriter.Where方法的具体用法?C# TextWriter.Where怎么用?C# TextWriter.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.TextWriter
的用法示例。
在下文中一共展示了TextWriter.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
private static void Write(string outDir, byte type)
{
Console.WriteLine("Writing ants of type {0} to {1}", type, outDir);
var outputs = new TextWriter[256];
var rand = new Random();
try
{
using (var cn = new SqlConnection("Data Source=.;Initial Catalog=AntHill;Integrated Security=true;"))
{
cn.Open();
using (var cmd = cn.CreateCommand())
{
cmd.CommandText = @"select Cells.Area, links.AntId, links.CellId
from ants
inner join links on ants.Id = links.AntId
inner join cells on cells.Id = links.CellId
where type = @type";
cmd.Parameters.AddWithValue("type", type);
using (var r = cmd.ExecuteReader(CommandBehavior.SingleResult))
{
Console.WriteLine("Got reader...");
var records = 0;
while (r.Read())
{
records++;
var area = r.GetByte(0);
area = (byte) rand.Next(0, 256);
if (outputs[area] == null)
outputs[area] = new StreamWriter(new FileStream(Path.Combine(outDir, "area-" + area.ToString("D3")), FileMode.Create, FileAccess.Write));
var writer = outputs[area];
writer.Write(r.GetGuid(1).ToString("N"));
writer.Write('\t');
writer.WriteLine(r.GetGuid(2).ToString("N"));
}
Console.WriteLine("Processed {0} records", records);
}
}
}
}
finally
{
outputs
.Where(o => o != null)
.Do(o => o.Close());
}
}