It is called an Explicit Cast. From MSDN:
Explicit conversions (casts): Explicit conversions require a cast operator. Casting is required when information might be lost in the conversion, or when the conversion might not succeed for other reasons. Typical examples include numeric conversion to a type that has less precision or a smaller range, and conversion of a base-class instance to a derived class
The method WebRequest.Create
returns an object of type WebRequest
, which is an abstract class, meaning an instance of it cannot be created, only an underlying derived type which inherits from WebRequest
. What the cast is doing in this case is telling the compiler: "Listen, i know Create
actually returns an HttpWebRequest
from this method, so let me treat it like one". When the cast is being done, it will either succeed if the actual type is a HttpWebRequest
or it will throw an InvalidCastException
if it isn`t