的String.Format或不? [英] String.Format or Not?

查看:194
本文介绍了的String.Format或不?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

特别是在C#中的世界用的String.Format的一切真的是常见的,通常为VB.NET开发,除非我必须*我不知道的String.Format,

Especially in C# world using String.Format for everything is really common, normally as VB.NET developer unless I have to* I don't String.Format,

我preFER正常的字符串连接,如:

I prefer normal string concatenation, such as:

V1 = V2 & "test-x" & V3 & "-;"

对我来说这是比这更好的:

to me it's better than this:

V1 = String.Format("{0} test-x {1} -;", V2, V3)

我缺少的东西?或者这只是一个个人preference?

Am I missing something? Or is this just a personal preference?

理由使用的String.Format(从答案)我会尽力保持这个最新的的)

  • 在本地化是那么容易得多,如果你使用字符串格式
  • 显然,这是容易改变输入的格式
  • 这是更具可读性(然而,这是个人的)
  • 更好的性能
  • Localization is so much easier if you use String Format
  • Obviously it's easier to change the format of input
  • It's more readable (however this is personal)
  • Better Performance

*的有时候,我需要改变风格或更换的东西动态然后我用的String.Format

推荐答案

如果你曾经要本地化您的应用程序(这往往很难排除这种可能性的开始),然后的String.Format是要大大preferred,有两个原因:

If you're ever going to localize your application (and it's often hard to rule that out at the start), then String.Format is to be much preferred, for two reasons:

  1. 您只有一个字符串翻译
  2. 您可以更改值的顺序,这可能是另一种语言更有意义。

这篇关于的String.Format或不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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