我们如何在.net framework 3.5中使用AppendAllLines [英] How can we use AppendAllLines in .net framework 3.5

查看:76
本文介绍了我们如何在.net framework 3.5中使用AppendAllLines的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AppendAllLines适用于.net framework 4.5

但我们如何使用追加3.5中的所有行

  //   4.5  
string [] a = < span class =code-keyword> new string [] {fa + < span class =code-string> + lastModified};
System.IO.File.AppendAllLines(filepath,a);

// 3.5
string [] a = new string [] {fa + + lastModified};
var ab = string .Join(Environment.NewLine,DataList.Select(x = < span class =code-keyword>> x.blah blah blah)。ToArray());
string outputFilePath = @ C:\\ \\output.txt;
File.AppendAllText(outputFilePath,ab);

public static void AppendAllLines( string path,IEnumerable< string> lines)
{
using var writer = new StreamWriter(path, true ))
foreach var line in 行)
writer.WriteLine(line);
}

解决方案

您不能在.NET 4.0之前的版本中使用File.AppendAllLines - 它已添加到点。



相反,您需要执行类似于您在问题中显示的string.Join代码。


< pre lang =cs> string [] a = new string [] {fa + + lastModified};
使用(TextWriter writer = File.AppendText(filepath))
{
foreach string actor in a)
{
writer.WriteLine (演员);
}
} Console.WriteLine(fa);


AppendAllLines is work in .net framework 4.5
but how can we use append all line in 3.5

//4.5
string[] a = new string[] { fa + " "+ lastModified };
System.IO.File.AppendAllLines(filepath, a);

//3.5
string[] a = new string[] { fa + " "+ lastModified };
var ab = string.Join(Environment.NewLine, DataList.Select(x => x.blah blah blah).ToArray());
string outputFilePath = @"C:\output.txt";
File.AppendAllText(outputFilePath, ab);

public static void AppendAllLines(string path, IEnumerable<string> lines)
{
     using (var writer = new StreamWriter(path, true))
         foreach (var line in lines)
             writer.WriteLine(line);
}

解决方案

You can't use File.AppendAllLines in version prior to .NET 4.0 - it was added at that point.

Instead, you would need to do something like the string.Join code you show in your question.


string[] a = new string[] { fa + " "+ lastModified };
                          using (TextWriter writer = File.AppendText(filepath))
                          {
                              foreach (string actor in a)
                              {
                                  writer.WriteLine(actor);
                              }
                          } Console.WriteLine(fa);


这篇关于我们如何在.net framework 3.5中使用AppendAllLines的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆