为什么要在C#中使用String.Concat()? [英] Why use String.Concat() in C#?

查看:492
本文介绍了为什么要在C#中使用String.Concat()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想了一会儿。为什么使用而不是使用加运算String.Concat()。我理解,因为使用加运算,让你的code旁观者更好的成为一个空隙的String.Format。

例如像

 串的一个=鲍勃;
线二=吉姆;

字串3 =一个+两台;
串3 = String.Concat(一,二);
 

解决方案

只要两个操作数都是字符串,没有任何区别在所有使用 + 运营商之间和 String.Concat 方法。使用 + 运营商的code实际上编译成一个 String.Concat 电话。

使用最重presents你的意图与code中的之一。

I been wondering this for a while. Why use String.Concat() instead of using the plus operator. I understand the String.Format since it a voids using the plus operator and make your code looker nicer.

like for example

string one = "bob";
string two = "jim";

string three = one + two;
string three = String.Concat(one,two);

解决方案

As long as the two operands are strings, there is no difference at all between using the + operator and the String.Concat method. The code using the + operator actually compiles into a String.Concat call.

Use the one that best represents your intention with the code.

这篇关于为什么要在C#中使用String.Concat()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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