asp.net - how to convert using statement in C#? -
I C # the following statement to convert I am working on asp.net and i wnt
< pre> as while HttpWebResponse = TryCast (request.GetResponse (), HttpWebResponse) using feedback dim reader new StreamReader (response.GetResponseStream (a)) is used as the St. = reader.ReadToEnd () end < / Code> If anyone knows, please tell me. Thank you in advance.
Good, a literal translation would be:
using HTTP webbase feedback = request.Getrespons ()) as HTTP (Reader Reader; New Stream Reader (Response .GetterSpenceScream); St = reader.ReadToEnd ();}
However If feedback not a HttpWebResponse
that still will fail - just a NullReferenceException
. I prefer to cast :
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse ()) {StreamReader reader = new StreamReader (response.GetResponseStream ()); St = reader.ReadToEnd ();}
or meticulous that response will be clear, even if it has to be a web response:
using (WebResponse response = request .GetResponse ()) {HttpWebResponse httpResponse = (HttpWebResponse) response; Strymrider reader = new Strymrider (httpResponse.GetResponsestream ()); St = reader.ReadToEnd (); }
... but WebResponse
is already included GetResponseStream
, so there is no need to cast to HttpWebResponse
In the first place, be honest.
Comments
Post a Comment