[英]Visual Studio 2012 Error “Does not contain a definition”
I am new to Visual Studio 2012 and C# in general. 我是Visual Studio 2012和C#的新手。 I created a simple Windows Forms Application project with just a few labels and textboxes.
我创建了一个简单的Windows Forms Application项目,其中仅包含几个标签和文本框。 I then decided to change the name of the .cs file of my application from Form1.cs to Application.cs.
然后,我决定将我的应用程序.cs文件的名称从Form1.cs更改为Application.cs。 Now there are 3 errors on the code-generated part in the Program.cs:
现在,Program.cs中的代码生成部分存在3个错误:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Application());
It says that my Application does not contain a definition for any of these methods. 它说我的应用程序不包含任何这些方法的定义。 I have not changed anything except refactored the file names.
除了重构文件名之外,我没有进行任何更改。 What am i missing here?
我在这里想念什么?
You're probably referencing the wrong Application
class: 您可能引用了错误的
Application
类:
http://msdn.microsoft.com/en-us/library/system.windows.forms.application(v=vs.110).aspx http://msdn.microsoft.com/zh-CN/library/system.windows.forms.application(v=vs.110).aspx
Use a different class name that doesn't clash or use a fully-qualified name with namespaces to disambiguate, ie: 使用不冲突的其他类名,或使用带有名称空间的完全限定名称来消除歧义,即:
MyProgram.AnotherNamespace.Application
System.Windows.Forms.Application
When you changed your Form1.cs class to Application.cs, you overwrote the default Application class, which is built into the .NET libraries. 当您将Form1.cs类更改为Application.cs时,您将覆盖默认的Application类,该类内置于.NET库中。 When trying to access the class using
尝试使用访问类时
Application.Run();
it believes you are actually trying to call the method "Run" in your defined class and not the original .NET class. 它认为您实际上是在尝试在定义的类而不是原始.NET类中调用方法“ Run”。
The only/best way to fix this issue is assign the created class a different name to something that does not already exist. 解决此问题的唯一/最佳方法是为创建的类分配一个不存在的名称。 It is the best standard to give new classes a name that is not already being used.
给新类一个尚未使用的名称是最好的标准。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.