它与response.write()和response.output.write()的区别是有问题的,谢谢你.
Gra*_*ton 26
看到这个:
Response.Write()和Response.Output.Write()ASP.NET 之间的区别.简短的回答是后者给你String.Format-style输出而前者没有.答案如下.
在ASP.NET中,Response对象是类型的HttpResponse,当你说Response.Write你真的在说(基本上)HttpContext.Current.Response.Write并调用其中一个重载Write方法时HttpResponse.
Response.Write然后调用.Write()它的内部TextWriter对象:
public void Write(object obj){ this._writer.Write(obj);} 
HttpResponse还有一个叫做Output类型的属性,是的TextWriter,所以:
public TextWriter get_Output(){ return this._writer; } 
这意味着你可以做Response任何TextWriter让你失望的事情.现在,TextWriters支持一种Write()方法String.Format,所以你可以这样做:
Response.Output.Write("Scott is {0} at {1:d}", "cool",DateTime.Now);
但在内部,当然,这种情况正在发生:
public virtual void Write(string format, params object[] arg)
{ 
this.Write(string.Format(format, arg)); 
}
小智 9
这里Response.Write():只显示字符串,你不能显示任何其他数据类型值,如int,date等.不允许转换(从一种数据类型到另一种数据类型).而Response .Output .Write():你可以通过给出索引值来显示任何类型的数据,如int,date,string等.
这是一个例子:
protected void Button1_Click(object sender, EventArgs e)
    {
       Response.Write ("hi good morning!"+"is it right?");//only strings are allowed        
       Response.Write("Scott is {0} at {1:d}", "cool", DateTime.Now);//this will give error(conversion is not allowed)
       Response.Output.Write("\nhi goood morning!");//works fine
       Response.Output.Write("Jai is {0} on {1:d}", "cool", DateTime.Now);//here the current date will be converted into string and displayed
    }
| 归档时间: | 
 | 
| 查看次数: | 95971 次 | 
| 最近记录: |