运行这段代码时出现编译错误:
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
private Dictionary<string, string> _dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); // let's ignore case when comparing.
protected void Page_Load(object sender, EventArgs e)
{
using (var reader = new StreamReader(File.OpenRead(@"C:/dictionary.csv")))
{
while (!reader.EndOfStream)
{
string[] tokens = reader.ReadLine().Split(';');
_dictionary[tokens[0]] = tokens[1];
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string output;
if (_dictionary.TryGetValue(TextBox1.Text, out output))
{
TextBox2.Text = output;
}
else
{
TextBox2.Text = "Input not recognised";
}
}
}
}
这是编译器错误消息:CS1061:“ASP.webform1_aspx”不包含“TextBox1_TextChanged”的定义,并且找不到接受“ASP.webform1_aspx”类型的第一个参数的扩展方法“TextBox1_TextChanged”(您是缺少 using 指令或程序集引用?)
这是什么意思,我该如何更正它? 谢谢
最佳答案
很可能在您的表单上,在 Visual Studio 中,有一个 TextBox1_TextChanged
方法在您的 TextBox
的 TextChanged
属性中声明,而那里没有实现。
您可能已经有了该实现(一个空方法),然后将其删除,而没有在 Visual Studio 的 UI 中删除对它的引用。因此,在 Visual Studio 中打开您的表单,单击 TextBox1
,在 TextChanged
属性中查找值并将其删除。
关于c# - 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20330841/