Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET equivalent for the C# 7 is operator declaration pattern

Tags:

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)
    {
        // ...
    }
}

Or the short pattern matching syntax with is is exclusive to C#?

EDIT:

I already know these syntaxes:

    If TypeOf obj Is Bitmap Then
        Dim bmp As Bitmap = obj
        ' ...
    End If

or

    Dim bmp As Bitmap = TryCast(obj, Bitmap)
    If bmp IsNot Nothing Then
        ' ...
    End If

What I want to know is whether there is something even shorter, like that new C#7 is operator declaration pattern...

Thank you very much.

like image 836
VBobCat Avatar asked Nov 26 '17 11:11

VBobCat


People also ask

Is VB.NET the same as C#?

Though C# and VB.NET are syntactically very different, that is where the differences mostly end. Microsoft developed both of these languages to be part of the same . NET Framework development platform. They are both developed, managed, and supported by the same language development team at Microsoft.

Is VB.NET similar to C++?

You are right, C++ and VB are two completely different languages and have quite a few fundamental differences (managed vs. unmanaged being a major one that comes to mind...).

Is VB.NET still used 2021?

It is a fact that coding languages never die. Even the oldest coding languages such as Classic Asp, VB6, COBOL, FORTRAN, VB.Net, etc. are still in use in few organizations.

Is VB.NET discontinued?

Visual Basic (VB.NET) will continue to be supported by Microsoft. (It's not dead.) The language will no longer have new features added to it.


1 Answers

Currently, no. If you want to implement this, you'll have to use some of the longer formats you already mention in your question.

The C# and VB languages don't always have equivalent features.

like image 119
simonalexander2005 Avatar answered Oct 19 '22 14:10

simonalexander2005