什么是的Response.Write()andResponse.Output.Write()之间的区别? [英] What’s the difference between Response.Write() andResponse.Output.Write()?
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/111417/whats-the-difference-between-response-write-and-response-output-write\">What’s的Response.Write()和Response.Output.Write()有什么区别?
它是如何从的Response.Write()和response.output.write()不同的解释问题地感谢ü。
how it is different from response.write() and response.output.write() explain problematically thank u.
推荐答案
看到这个:
在ASP.NET 的Response.Write()
和 Response.Output.Write()
之间的区别。简短的答案是后者给你的String.Format风格
输出与前者没有。长的答案如下:
The difference between Response.Write()
and Response.Output.Write()
in ASP.NET. The short answer is that the latter gives you String.Format-style
output and the former doesn't. The long answer follows.
在ASP.NET中的响应
对象的类型为的Htt presponse
键,当你说的Response.Write
你是真心的(基本上) HttpContext.Current.Response.Write
并调用许多重载之一发表
的Htt presponse $ C $的C
方法>。
In ASP.NET the Response
object is of type HttpResponse
and when you say Response.Write
you're really saying (basically) HttpContext.Current.Response.Write
and calling one of the many overloaded Write
methods of HttpResponse
.
的Response.Write
然后调用 .WRITE()
在它的内部的TextWriter
目标:
Response.Write
then calls .Write()
on it's internal TextWriter
object:
public void Write(object obj){ this._writer.Write(obj);}
的Htt presponse
也有一个名为输出
属性,它的类型是的,是的,<$ C的$ C>的TextWriter ,所以:
HttpResponse
also has a Property called Output
that is of type, yes, TextWriter
, so:
public TextWriter get_Output(){ return this._writer; }
这意味着你可以到的响应任何一个
的TextWriter
会让你。现在,TextWriters支持阿拉的String.Format
A 写()
的方法,所以你可以这样做:
Which means you can to the Response
whatever a TextWriter
will let you. Now, TextWriters support a Write()
method ala String.Format
, so you can do this:
Response.Output.Write("Scott is {0} at {1:d}", "cool",DateTime.Now);
但在内部,当然,这这种情况正在发生:
But internally, of course, this this is happening:
public virtual void Write(string format, params object[] arg)
{
this.Write(string.Format(format, arg));
}
这篇关于什么是的Response.Write()andResponse.Output.Write()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!