在C#中,什么是存储一组我的程序使用常数的最佳方式? [英] In C#, what's the best way to store a group of constants that my program uses?

查看:75
本文介绍了在C#中,什么是存储一组我的程序使用常数的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的程序使用各种常数。有些是字符串 S,有些是 INT S,还有一些是双击秒。什么是存储它们的最好方法?我不认为我想要一个枚举,因为数据是各不相同的类型,我想手动设置每个值。如果我只是他们都存储在一个空类,还是有更好的办法?

I have various constants that my program uses. Some are strings, some are ints, and some are doubles. What's the best way to store them? I don't think I want an Enum, because the data is not all the same type, and I want to manually set each value. Should I just store them all in an empty class, or is there a better way?

推荐答案

您也许可以让他们在一个静态类,静态只读属性。

You probably could have them in a static class, with static read-only properties.

public static class Constants
{
   public static string SomeConstant { get { return "Some value"; } }
}

这篇关于在C#中,什么是存储一组我的程序使用常数的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆