简体   繁体   English

Visual Studio 2012错误“不包含定义”

[英]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.

相关问题 Visual Studio 2013 报告最近扩展方法的错误“不包含定义”错误 - Visual Studio 2013 reporting erroneous "does not contain a definition for" error for recent extension methods 错误'System.Diagnostics.Process'在Visual Studio 2008 C#中不包含'GetProcesses'的定义 - Error 'System.Diagnostics.Process' does not contain a definition for 'GetProcesses' in visual studio 2008 c# C# - Visual Studio - “object”不包含“ExecuteQuery”的定义 - C# - Visual Studio - 'object' does not contain a definition for 'ExecuteQuery' 剃刀错误:不包含定义 - Razor error : does not contain a definition for Visual Studio 2012 + 403.7错误 - Visual Studio 2012 + 403.7 Error 为什么Visual Studio 2010告诉我“'System.Delegate'不包含'EndInvoke'的定义”? - Why is Visual Studio 2010 telling me “'System.Delegate' does not contain a definition for 'EndInvoke'”? 我不断收到“MainWindow”在 Visual Studio WPF 应用程序中不包含“FadeOut”的定义 - I keep getting 'MainWindow' does not contain a definition for 'FadeOut' in Visual Studio WPF Application Visual C#错误:System.Windows.Forms.Button不包含ToInt32的定义 - Visual C# Error: System.Windows.Forms.Button does not contain a definition for ToInt32 Visual Studio 2012 C#转到定义始终返回元数据 - visual studio 2012 c# go to definition always returns metadata Visual Studio 2012是否会自动转换货币? - Does Visual Studio 2012 automatically converts currency?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM