字符串插值VS的String.Format [英] String Interpolation vs String.Format

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

问题描述

有没有使用字符串插值之间的noticable性能差异:

Is there a noticable performance difference between using string interpolation:

myString += $"{x:x2}";



VS的String.Format()?

vs String.Format()?

myString += String.Format("{0:x2}", x);



我只问,因为ReSharper的是促使修复和我之前已经忽悠了。

I am only asking because Resharper is prompting the fix, and I have been fooled before.

推荐答案

Noticable是相对的。但是:串插在编译时变成的String.format()所以他们应该具有相同的结果结束了

Noticable is relative. However: string interpolation is turned into string.Format() at compile-time so they should end up with the same result.

有细微的差别,但:正如我们从的这个问题,在额外的 string.Concat()调用格式说明结果字符串连接。

There are subtle differences though: as we can tell from this question, string concatenation in the format specifier results in an additional string.Concat() call.

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

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