繁体   English   中英

所有 forms 类均可访问的全局配置变量?

[英]A global variable of configuration accessible to all the forms classes?

我有一个 winform c# 项目。 它有多种形式/类。 我在 app.config 中有一个键控字符串,并希望在所有表单/类中使用它。

我要不要在每个表格 class 中创建一个字符串类型的字段,并从 app.config 中读取值,并将值分配给该字段?

还是有一个 class,这样我就可以只为那个 class 创建一个字段,从 app.config 中读取一次值,并将其分配给该字段一次,然后让其他 forms 类引用它?

谢谢。

为什么不使用共享配置数据创建 static class?

public static class ConfigData
{
  public static string ConfigString1 {get;set;}
  public static int ConfigInt1 {get;set;}

}

并添加“使用 static yournamespace.ConfigData;” 到您需要配置数据的任何 class 文件

暂无
暂无

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

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