我有几个静态字段,需要知道什么是最适合它们的容器:class 还是 struct?
public class/struct MySharedFields
{
public static readonly string Field1 = AppConfig.GetValue("Field1");
public static readonly string Field2 = AppConfig.GetValue("Field2");
public static readonly string Field3 = AppConfig.GetValue("Field3");
}
请您参考如下方法:
通常静态类是要走的路,但它真的没有什么区别。加号是您可以在将来根据需要添加方法。
public static class MySharedFields
{
public static readonly string Field1 = AppConfig.GetValue("Field1");
public static readonly string Field2 = AppConfig.GetValue("Field2");
public static readonly string Field3 = AppConfig.GetValue("Field3");
}
