简体   繁体   中英

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

我只是想知道为什么它是Settings.Default.<mysetting>而不仅仅是Settings.<mysetting>

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.

当Settings.CompanyName可以创建为返回实例值的Property时,使用Settings.Default.CompanyName是没有意义的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM