编译错误c#
我有大量的代码在Visual Studio中编译,但是在不同的IDE中它不能编译。编译错误c#
返回的错误是System.IO文件不包含“ReadLines”的定义。
我使用system.io
与一个eror出现的代码的部分是readlines方法。
有人可以提供灵魂吗?
using System;
using System.IO; // enable the user of different sections of the .net framework
using System.Linq;
using System.Collections.Generic;
namespace HashTagAssignment
{
class HashTag
{
static void Main(string[] args)
{
string tweets = File.ReadAllText(@"F:\tweets.txt"); // Retrives Text from file and loads into console
{
Console.WriteLine(tweets); // writes contense to console
{
var lineCount = File.ReadAllLines(@"F:\tweets.txt").Length; // counts number of lines in the whole document
Console.WriteLine("Number of Lines:{0}", lineCount); // displays answer
{
var result = File.ReadLines(@"F:\tweets.txt").Distinct().Count(); // search txt file for Distinct enteries and implement counter.
Console.WriteLine(" Number of Unique Tags: {0}", result); // display result of counter
{
Console.WriteLine(" Top Twenty By Number:"); // Title Top twenty hash tags, with order they occured in left colum.
Console.WriteLine(); // creates a line space
var rank = File // assigns varible to a file
.ReadLines(@"F:\tweets.txt") // directs to file, in this case text
.GroupBy(x => x)
.Select(g => new { Key = g.Key, Count = g.Count() })
.OrderByDescending(i => i.Count)
.Take(20);
foreach (var item in rank)
{
Console.WriteLine("{0} {1}", item.Count, item.Key);
}
{
{
}
Console.ReadKey(true);
}
}
}
}
}
}
}
}
File.ReadLines
方法是.Net 4.0的新方法。
他们是替代我可以使用3.5和以下? – Evildommer5
我使用的编译器是sharpdevelop – Evildommer5
@ Evildommer5您可以使用['File.ReadAllLines'](http://msdn.microsoft.com/en-us/library/system.io.file.readalllines(v = VS.80 ).aspx)而不是(.NET 2.0+),但是这不会像'ReadLines'那样懒惰地列举。 – vcsjones
File.ReadLines在.NET 4.0之前不可用。您需要确保您正在编译.NET 4.0+或Mono的兼容版本。
如果您只是在其他IDE中发现此错误,请确保您的解决方案/项目(如果其他IDE甚至使用它)有包含它的程序集的引用。我认为这是mscorlib.dll。
编辑:只是好奇,什么IDE?
sharpdevelop ide – Evildommer5
SharpDevelop是否不支持.NET 4?为什么从VS切换? –
因为我需要确保它编译的计算机上我没有vs – Evildommer5
后哟代码哟。 –
让我们看看代码和错误? –
我们是否想要猜测其他IDE?也许你试图在Netbeans中编译你的C#程序。 –