The Artima Developer Community
Sponsored Link

.NET Buzz Forum
ASP.NET, Response.Write and Response.Output.Write - know the difference

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Scott Hanselman

Posts: 1031
Nickname: glucopilot
Registered: Aug, 2003

Scott Hanselman is the Chief Architect at Corillian Corporation and the Microsoft RD for Oregon.
ASP.NET, Response.Write and Response.Output.Write - know the difference Posted: Jan 3, 2004 12:57 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Scott Hanselman.
Original Post: ASP.NET, Response.Write and Response.Output.Write - know the difference
Feed Title: Scott Hanselman's ComputerZen.com
Feed URL: http://radio-weblogs.com/0106747/rss.xml
Feed Description: Scott Hanselman's ComputerZen.com is a .NET/WebServices/XML Weblog. I offer details of obscurities (internals of ASP.NET, WebServices, XML, etc) and best practices from real world scenarios.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Scott Hanselman
Latest Posts From Scott Hanselman's ComputerZen.com

Advertisement

A fellow emailed me just now wanting to know the difference between Response.Write() and Response.Output.Write() in ASP.NET.  Well sir, I'm glad you asked, because it's damned interesting. :)  The short answer is that the latter gives you String.Format-style output and the former doesn't.  The long answer follows.

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 then calls .Write() on it's internal TextWriter object:

public void Write(object obj){ this._writer.Write(obj);}

HttpResponse also has a Property called Output that is of type, yes, TextWriter, so:

public TextWriter get_Output(){ return this._writer; }

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)); 
}

>

Read: ASP.NET, Response.Write and Response.Output.Write - know the difference

Topic: Another one bites the bullet: Santo has left the building Previous Topic   Next Topic Topic: MSDN killing trees/spirit unnecessarily

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use