我应该使用字符串常量或字符串 [英] Should I use string constants or string literals

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

问题描述

在默认情况下我使用的字符串常量在我的code,当我有文字,将输出到屏幕上,通过一个消息框,标签,串等等。我的主要理由这样做,我不希望这些字符串在运行时改变这种方式,没有人真正接触他们。

By default I use string constants in my code when I have a string of text that will be output to the screen via a messagebox, label, etc. My main reason for doing so is that I do not want these strings to change at runtime and this way nobody really touches them.

我的问题是:

这似乎从一个记忆点,这种方法是创建一个对象,其寿命将通过国标,而一个字符串文字似乎更高效,将更快地处理决定。我知道这是一个菜鸟的问题,但有一个好处(无论多么微小的)使用文字时,在一个恒定的还是应该在这样的情况下恒定的使用。

It seems that from a memory point of view, this approach is creating an object whose lifetime will be decided by the GB whereas a string literal seems more efficient and will be disposed of more quickly. I know this is a rookie question but is there a benefit (no matter how tiny) when using a literal over a constant or should a constant be used in such scenarios.

我知道这不会做出任何明显的区别在我的应用程序,但我想提高自己作为开发和建设,我保持了一个合理的时间标准。 :O)

I know it will not make any noticeable difference in my apps but I am trying to improve myself as a dev and build standards that I keep a reasonable amount of the time. :o)

推荐答案

都不是。推荐的方法AFAIK是使用一个资源文件。

Neither. The recommended way AFAIK is to use a resources file.

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

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