[英]Solution Explorer for Visual Studio C# 2013 Express
I'm running VS 2013 Express targetting 4.5. 我正在运行VS 2013 Express,目标是4.5。 I have a Windows Forms test app called ConfigMgrTest2. 我有一个名为ConfigMgrTest2的Windows窗体测试应用程序。 Two questions as I move around the Solution Explorer: 在解决方案资源管理器中移动时,有两个问题:
(1) Using the Settings Designer tool, I created an Application setting called 'applicationSetting1'. (1)使用设置设计器工具,创建了一个名为“ applicationSetting1”的应用程序设置。 To access this setting, I need this syntax: 要访问此设置,我需要以下语法:
var r = ConfigMgrTest2.Properties.Settings.Default.applicationSetting1;
I don't understand why I need to call this through the Default property. 我不明白为什么我需要通过Default属性来调用它。 Both Default and 'applicationSetting' are members of the Settings class. Default和'applicationSetting'都是Settings类的成员。 And 'Default' pertains to the 'defaultInstance' Why not call my 'applicationSetting' directly like this: 和“默认”属于“ defaultInstance”,为什么不这样直接调用我的“ applicationSetting”:
var r = ConfigMgrTest2.Properties.Settings.applicationSetting1;
(2) The Settings class is created in two parts. (2)设置类分为两个部分。 In the Settings.Designer.cs file, the Default property is created. 在Settings.Designer.cs文件中,创建Default属性。 In Settings.cs, the Settings event handlers are created. 在Settings.cs中,将创建Settings事件处理程序。 In one of my projects, I can see the Settings.cs file in Solution Explorer but in another, I seem to be missing this node. 在我的一个项目中,我可以在解决方案资源管理器中看到Settings.cs文件,但在另一个项目中,我似乎缺少此节点。
Your setting ( applicationSetting1
in this case) is an instance member of the Settings
class. 您的设置(在这种情况下为applicationSetting1
)是Settings
类的实例成员。 The Default
property represents an instance of that class via a Singleton pattern. Default
属性通过Singleton模式表示该类的实例。 In order to do what you want to do in your second example you would constantly need to be creating an instance of Settings
in your code, for example: 为了执行第二个示例中想要做的事情,您将不断需要在代码中创建一个Settings
实例,例如:
var settings = new ConfigMgrTest2.Properties.Settings();
var r = settings.applicationSetting1;
This would be a pain for the develop and also potentially leave you with several instances of the class hanging around. 这将给开发人员带来痛苦,并可能使您陷入课堂上的几个实例中。
I just took a look in my copy of Visual Studio 2013 (Professional). 我只是看了一下我的Visual Studio 2013(专业版)副本。 I see the Settings.settings file, which is an XML file, and the Settings.Designer.cs file, which is the C# code that actually generates the Settings
class code. 我看到Settings.settings文件(这是一个XML文件)和Settings.Designer.cs文件(这是实际上生成Settings
类代码的C#代码)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.