与 C# 7 等效的 VB.NET 是运算符声明模式 [英] VB.NET equivalent for the C# 7 is operator declaration pattern
本文介绍了与 C# 7 等效的 VB.NET 是运算符声明模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有与 C#7 是运算符声明模式?特别注意以下代码示例中的 bmp
:
Is there a VB.NET equivalent to the C# 7 is operator declaration pattern? Note in particular the bmp
in the following code sample:
public void MyMethod(Object obj)
{
if (obj is Bitmap bmp)
{
// ...
}
}
或者is
的短模式匹配语法是C#独有的?
Or the short pattern matching syntax with is
is exclusive to C#?
我已经知道这些语法:
If TypeOf obj Is Bitmap Then
Dim bmp As Bitmap = obj
' ...
End If
或
Dim bmp As Bitmap = TryCast(obj, Bitmap)
If bmp IsNot Nothing Then
' ...
End If
我想知道是否有更短的内容,例如 新的 C#7 是运算符声明模式...
What I want to know is whether there is something even shorter, like that new C#7 is operator declaration pattern...
非常感谢.
推荐答案
目前,没有.如果您想实现这一点,则必须使用您在问题中已经提到的一些较长的格式.
Currently, no. If you want to implement this, you'll have to use some of the longer formats you already mention in your question.
C# 和 VB 语言并不总是具有相同的功能.
The C# and VB languages don't always have equivalent features.
这篇关于与 C# 7 等效的 VB.NET 是运算符声明模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文