I'm using Visual Studio v12.0 and looking at the Settings.Designer.cs file in the Solution Explorer. In the Properties namespace, the Settings derived class is created from ApplicationSettingsBase class like so:
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
In the class, this line of code has me confused:
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
This is an example of downcasting, I believe. I'm not clear why this is necessary. Why not just create an instance of Settings since it's already defined as inheriting the base?
Here's a longer snippet:
namespace ConfigMgrTest.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
...rest of the namespace...
}