as operator can and will return
null if the object you're trying to cast cannot be converted to the target type.
Type-testing operators and cast expression - C# reference | Microsoft Docs[^]
as when you're not sure whether the object can be converted to the specified type; in which case, you should always check for
null before using the variable. Using
T y = x as T; without then checking for
y == null is always a mistake.
When you're certain that the object will be of the desired type, you use a cast expression instead:
T y = (T)x; In this case, there is no need to check for
null, since the runtime would throw an exception if the conversion cannot be performed.
However, in this case, it would be far better to simply use the
WebRequest.CreateHttp method, which has been available since .NET 4.5, and already returns the correct type:
WebRequest.CreateHttp Method (System.Net) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."