這是更加概念性的問題,因爲我是新來的C#試圖讓一個簡單的瞭解。錯誤命名空間訪問庫C#
我試圖讀取文本文件,其中工程細紋,但我想實現以下解決方案來讀取的最後一行,以及,但它給了以下錯誤:
錯誤1「System.Collections中.Generic.IEnumerable」不包含用於定義‘最後一個’和沒有擴展方法‘最後一個’接受型的第一參數‘System.Collections.Generic.IEnumerable’可以找到(是否缺少using指令或程序集引用?)
代碼:
using System;
using System.IO;
using System.Collections;
class Program
{
public static void Main()
{
int counter = 0;
string line;
string xml_files;
// string jpg_files;
System.IO.StreamReader file = new System.IO.StreamReader(@"C:\test\logfile_c#.txt");
string lastLine = File.ReadLines(@"C:\test\logfile_c#.txt").Last();
while ((line = file.ReadLine()) != null)
{
Console.WriteLine(line);
Console.WriteLine(counter);
Console.Read();
counter++;
}
}
}
有人可以幫助我更好地瞭解如何避免這個問題。
謝謝!
舊的文章(回答你的問題)由@約翰飛碟雙向http://stackoverflow.com/questions/2659290/ienumerable-doesnt-have-count回答 – Rahul