C# Settings File: Why do I have to use Settings.Default?
Asked Answered
A

2

7

I'm just wondering why it's Settings.Default.<mysetting> instead of just Settings.<mysetting>?

Ashanti answered 10/1, 2011 at 13:59 Comment(0)
E
10

Simply put: because Settings is a class, and the properties are instance properties. So you need an instance, and the default way of creating an instance is through the Default property.

The obvious followup question is why the properties aren't just static to start with... and I surmise that the answer is that it's useful to be able to create settings in ways other than with the default settings load/save approach... for example, loading them from a database, or from a different file path.

Eventful answered 10/1, 2011 at 14:2 Comment(0)
S
1

It doesn't make sense to use Settings.Default.CompanyName when Settings.CompanyName can be created as Property returning the instance's value.

Sigler answered 1/8, 2011 at 18:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.