简体   繁体   English

C#更改设置文件名

[英]C# change settings file name

In C#, is it possible to change the "Default" name for the settings file without having to create an additional settings file? 在C#中,是否可以更改设置文件的“默认”名称而无需创建其他设置文件? For example, instead of using: 例如,而不是使用:

Properties.Settings.Default.Setting1

I want to use: 我想用:

Properties.Settings.Group1.Setting1 and Properties.Settings.Group2.Setting2 Properties.Settings.Group1.Setting1Properties.Settings.Group2.Setting2

Remember that Settings is a partial class. 请记住, Settings是一个部分类。 You can write a partial class Settings with your own properties. 您可以使用自己的属性编写partial class Settings In my opinion, this is exactly why it is a partial class. 在我看来,这正是为什么它是一个部分类。

I wouldn't recommend changing the default Default property. 我不建议更改默认的 Default属性。 You can, however write the following: 但是,您可以写下以下内容:

public partial class Settings {

   // provide custom Groups, etc.
   public void Group1 {
      // some specific collection or object
      return Group1.Settings
   }

   public void Group2 {
      // some specific collection or object
      return Group2.Settings
   }
}

...where Group1 and Group2 represent custom classes. ...其中Group1Group2代表自定义类。 Each Group object can have their own methods for saving data, settings, configurations, etc. 每个Group对象都可以有自己的方法来保存数据,设置,配置等。

When you update your setting, add this code to persist 更新设置时,请添加此代码以保留

Properties.Settings.OtherName.Setting1 = ...;
Properties.Settings.OtherName.Save();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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