什么是.NET 3.5相当于WriteAllLines在我的code? [英] What is the .NET 3.5 equivalent of WriteAllLines in my code?

查看:111
本文介绍了什么是.NET 3.5相当于WriteAllLines在我的code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var output = query.Select(x => x.Plant + "\t" + x.Animal + "\t" + blah blah blah);
string FilePath = @"C:\output.txt";
File.WriteAllLines(FilePath, output);

我的时候切换目标框架,从4.0到3.5得到的错误是:

The error I get when switching the target framework from 4.0 to 3.5 is:

错误14的最佳重载方法匹配System.IO.File.WriteAllLines(字符串,字符串[])'有一些无效的参数

Error 14 The best overloaded method match for 'System.IO.File.WriteAllLines(string, string[])' has some invalid arguments

什么是使切换到3.5框架,而不必改变太多code,仍然保持其功能的最简单的方法是什么?

What is the easiest way to make the switch to the 3.5 Framework without having to change too much code and still keep its functionality?

推荐答案

的的 File.WriteAllLines >接受的String [] 。在.NET 4.0 有过载 IEnumerable的<字符串> ,这就是为什么你原来的code ++工程。使用一个数组,而不是和你应该罚款:

The .NET 3.5 overload of File.WriteAllLines accepts a string[]. In .NET 4.0 there's an overload for IEnumerable<string>, which is why your original code works. Use an array instead and you should be fine:

File.WriteAllLines(FilePath, output.ToArray());

这篇关于什么是.NET 3.5相当于WriteAllLines在我的code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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