2011-11-23 161 views
-5

我有大量的代碼在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); 
          } 
         } 
        } 
       } 
      } 
     } 
    } 
} 
+1

後喲代碼喲。 –

+0

讓我們看看代碼和錯誤? –

+3

我們是否想要猜測其他IDE?也許你試圖在Netbeans中編譯你的C#程序。 –

回答

10

File.ReadLines方法是.Net 4.0的新方法。

+0

他們是替代我可以使用3.5和以下? – Evildommer5

+0

我使用的編譯器是sharpdevelop – Evildommer5

+0

@ Evildommer5您可以使用['File.ReadAllLines'](http://msdn.microsoft.com/en-us/library/system.io.file.readalllines(v = VS.80 ).aspx)而不是(.NET 2.0+),但是這不會像'ReadLines'那樣懶惰地列舉。 – vcsjones

1

File.ReadLines在.NET 4.0之前不可用。您需要確保您正在編譯.NET 4.0+或Mono的兼容版本。

0

如果您只是在其他IDE中發現此錯誤,請確保您的解決方案/項目(如果其他IDE甚至使用它)有包含它的程序集的引用。我認爲這是mscorlib.dll。

編輯:只是好奇,什麼IDE?

+0

sharpdevelop ide – Evildommer5

+0

SharpDevelop是否不支持.NET 4?爲什麼從VS切換? –

+0

因爲我需要確保它編譯的計算機上我沒有vs – Evildommer5