VB.NET等效于C#7类型模式匹配 [英] VB.NET equivalent for C# 7 Type pattern matching

查看:65
本文介绍了VB.NET等效于C#7类型模式匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有与此等效的VB.NET? 请特别注意代码示例中的 bmp

Is there a VB.NET equivalent to this? Note in particular the bmp in the code sample.

public void MyMethod(Object obj)
{
    if (obj is Bitmap bmp)
    {
        // ...
    }
}

或者带有的短模式匹配语法是是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 syntax...

非常感谢你ch。

推荐答案

当前没有。如果要实现此目的,则必须使用在问题中已经提到的一些较长的格式。

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.

这篇关于VB.NET等效于C#7类型模式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆