存储常用常量 [英] Store commonly used Constants

查看:73
本文介绍了存储常用常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将常用常量存储到静态类中是一种好方法吗?如果没有,那么做这件事的有效方法是什么?需要建议.

谢谢和问候,

GPUToaster

Is it a good way to store commonly used constants to a static class? If not then what can be the efficient way to do the same? Need Suggestions.

Thanks and Regards,

GPUToaster

推荐答案

我通常根据程序集的恒定"程度将其放入标准的Properties.Settings类中.这意味着您可以在逐个环境的基础上修改常量".

如果无论如何总是一样,那么包含常量的静态类就是任何一种都很好的方法-您可以将它们公开为只读属性,但可以使用公共常量字段.

对于恒定的大文本块...说长参数化的TSQL语句...我已经将程序集资源"重新利用到了,因为复制和粘贴多行文本比必须转换成多行文本要容易得多/来自多行字符串.

希望这会有所帮助.
Depending on how ''constant'' it is I usually put things into the standard Properties.Settings class for the assembly. This means you can amend the ''constant'' on an environment by environment basis.

If it''s always going to be same regardless, then a static class containing the constant is as good a way as any - you could expose them as readonly properties but a public constant field will work.

For large blocks of text that are constant...say long paramterised TSQL statments... I''ve ''repurposed'' the assembly resources to as it''s much easier to copy and paste multiline text than having to convert to/from a multiline string.

Hope this helps.


这篇关于存储常用常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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