VB.NET 相当于 C#“As”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2450185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.NET equivalent of C# "As"
提问by JoelFan
What is the equivalent in VB.NET of the C# Askeyword, as in the following?
VB.NET 中 C# As关键字的等效项是什么,如下所示?
var x = y as String;
if (x == null) ...
回答by Hans Passant
回答by Morten Anderson
Trycast is what you're looking for.
Trycast 正是您要找的。
Dim x = TryCast(y, String)
回答by Guffa
TryCast:
试播:
Dim x = TryCast(y, String)
if (x Is Nothing) ...
回答by Alex Essilfie
Here you go:
干得好:
C# code:
C#代码:
var x = y as String;
if (x == null) ...
VB.NET equivalent:
VB.NET 等效项:
Dim x = TryCast(y, String)
If (x Is Nothing) ...
回答by Oskar Kjellin
Dim x = TryCast(y, [String])
Dim x = TryCast(y, [String])
回答by Dustin Laine
Dim x = TryCast(y, [String])
From: http://www.developerfusion.com/tools/convert/csharp-to-vb/
来自:http: //www.developerfusion.com/tools/convert/csharp-to-vb/
回答by evanboissonnot
You can use it with ?:
您可以将其用于?:
TryCast(item, String)?.Substring(10)
It allows you to manage nullable without if:)
它允许您在没有if:) 的情况下管理可空值

