我有这个代码用于c#读取TestFile.txt中的所有行但是当我读完时我想再读它然后把它放在一个字符串数组(不是List)中但是当我尝试再做一次时它说的是文件已被使用.我想重置流或执行类似sr.Close()的操作,因为我第一次读它时想要计算Testfile.txt中有多少行.
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试在while循环之后放置if(line == null)sr.Close()但它不起作用.
如何从扩展到接口的类实现方法?
我有这个界面:
public Interface myInterface
{
public static int myMethod();
}
Run Code Online (Sandbox Code Playgroud)
而这堂课:
public class MyClass : myInterface
{
// And I want here to implement the method form myInterface and i don't know how
}
Run Code Online (Sandbox Code Playgroud)