G
Guest
What is the benefit of using "as" vs the other?
HttpWebRequest myReq
= (HttpWebRequest)WebRequest.Create("http://www.contoso.com/");
vs.
HttpWebRequest myReq = WebRequest.Create("http://www.contoso.com/") as
HttpWebRequest;
Based on the MS documenation "The as operator is like a cast except that it
yields null on conversion failure instead of raising an exception. "
I've read some internal coding standards that state "Use the as operator to
defensively cast to a type", but I don't quite get the benefit of this and
want an outside opinion.
Thanks.
HttpWebRequest myReq
= (HttpWebRequest)WebRequest.Create("http://www.contoso.com/");
vs.
HttpWebRequest myReq = WebRequest.Create("http://www.contoso.com/") as
HttpWebRequest;
Based on the MS documenation "The as operator is like a cast except that it
yields null on conversion failure instead of raising an exception. "
I've read some internal coding standards that state "Use the as operator to
defensively cast to a type", but I don't quite get the benefit of this and
want an outside opinion.
Thanks.