StreamReader StringWriter定义了一个变量之后,编译器就不认识了?为什么,是不是要加载什么头文件?
StringWriter wr = new StringWriter();
wr.WriteLine("Friendship is not a two way road.");
wr.WriteLine("It is a one way road travelled by two people.");
wr.Write(Writer.NewLine);
wr.close();
Console.WriteLine("Data: {0}",wr.ToString());
请各位看看
StringWriter wr = new StringWriter();
wr.WriteLine("Friendship is not a two way road.");
wr.WriteLine("It is a one way road travelled by two people.");
wr.Write(Writer.NewLine);
wr.close();
Console.WriteLine("Data: {0}",wr.ToString());
请各位看看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace TestOne_09_7_7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void open_Click(object sender, EventArgs e)
{
// openFileDialog.ShowDialog();
new System.IO.StreamReader SR;
string S;
SR = File.OpenText(filename);
S = SR.ReadLine();
while (S != null)
{
Console.WriteLine(S);
S = SR.ReadLine();
}
SR.Close();
}
}
}
==>
System.IO.StreamReader SR;
楼主 C 转过来的?
代码有错,除了2楼说的,还少引用了 System.IO
修正如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
// openFileDialog.ShowDialog();
System.IO.StreamReader SR;
string S;
SR = File.OpenText(filename);
S = SR.ReadLine();
while (S != null)
{
Console.WriteLine(S);
S = SR.ReadLine();
}
SR.Close(); }
}
}