本文整理匯總了C#中System.IO.File.AppendAllLines方法的典型用法代碼示例。如果您正苦於以下問題:C# File.AppendAllLines方法的具體用法?C# File.AppendAllLines怎麽用?C# File.AppendAllLines使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.File
的用法示例。
在下文中一共展示了File.AppendAllLines方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.IO;
using System.Linq;
class Program
{
static string dataPath = @"c:\temp\timestamps.txt";
static void Main(string[] args)
{
CreateSampleFile();
var JulyWeekends = from line in File.ReadLines(dataPath)
where (line.StartsWith("Saturday") ||
line.StartsWith("Sunday")) &
line.Contains("July")
select line;
File.WriteAllLines(@"C:\temp\selectedDays.txt", JulyWeekends);
var MarchMondays = from line in File.ReadLines(dataPath)
where line.StartsWith("Monday") &&
line.Contains("March")
select line;
File.AppendAllLines(@"C:\temp\selectedDays.txt", MarchMondays);
}
static void CreateSampleFile()
{
DateTime TimeStamp = new DateTime(1700, 1, 1);
using (StreamWriter sw = new StreamWriter(dataPath))
{
for (int i = 0; i < 500; i++)
{
DateTime TS1 = TimeStamp.AddYears(i);
DateTime TS2 = TS1.AddMonths(i);
DateTime TS3 = TS2.AddDays(i);
sw.WriteLine(TS3.ToLongDateString());
}
}
}
}