哪些方法在3.5框架具有的String.Format般的签名? [英] Which methods in the 3.5 framework have a String.Format-like signature?

查看:137
本文介绍了哪些方法在3.5框架具有的String.Format般的签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到,我能做到以下几点,它来作为一个完整的惊喜给我:

I just noticed that I can do the following, which came as a complete surprise to me:

Console.WriteLine("{0}:{1}:{2}", "foo", "bar", "baz");

本作品为方法了。还有什么其他方法都有签名支持这一点,而无需使用的String.Format

This works for the Write method too. What other methods have signatures supporting this, without requiring the use of String.Format?

的Debug.WriteLine 不...
的Htt presponse.WriteLine 不...

Debug.WriteLine doesn't...
HttpResponse.WriteLine doesn't...

(并在一个侧面说明,我无法找到该搜索用的反光。什么是搜索特定签名的好方法吗?)

(And on a side note, I could not find a quick way of searching for this with Reflector. What is a good way to search for specific signatures?)

编辑:

专门针对3.5框架。

推荐答案

有很多支持这一整个框架方法。 TextWriter的所有子类(因此的StreamWriter 和<一HREF =htt​​p://msdn.microsoft.com/en-us/library/system.io.stringwriter.aspx相对=nofollow>的StringWriter 及其子类)将继承的方法。

There are a lot of methods that support this throughout the framework. All subclasses of TextWriter (and therefore StreamWriter and StringWriter and their subclasses) will inherit the Write method that supports this.

这是常用又如 StringBuilder.AppendFormat

您可以编写自己的方法来支持这一点。您可以通过具有过载与格式字符串参数,并与 PARAMS 关键字另一个参数,这样做的:

You can write your own methods to support this too. You can do it by having an overload with a format string parameter and another parameter with the params keyword, like this:

public void Foo(string message) {
    // whatever
}

public void Foo(string format, params string[] arg) {
    Foo(string.Format(format, arg));
}

这篇关于哪些方法在3.5框架具有的String.Format般的签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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