如何TryCast转换成C#? [英] How to convert TryCast in c#?
本文介绍了如何TryCast转换成C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何以下VB code转换到C#
how to convert following vb code in to c#
Dim request As HttpWebRequest = TryCast(WebRequest.Create(address), HttpWebRequest)
我尝试了使用与操作员在C#中,但它不工作。
i tried it using AS operator in c# but its not working.
感谢您提前。
推荐答案
您可以为
投用;这不会引发任何异常,但返回空
如果转换是不可能的(就像 TryCast
)
You can cast using as
; this will not throw any exception, but return null
if the cast is not possible (just like TryCast
):
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
这篇关于如何TryCast转换成C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文