VB.NET equivalent to match a C # 7 type pattern

Is there any VB.NET equivalent to this? Pay particular attention to bmp in the sample code.

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

Or a short syntax matching pattern with is exclusively for 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 

I want to know if there is something even shorter, like the new C # 7 syntax ...

Thank you very much.

+8
source share
2 answers

Not at present. If you want to implement this, you will have to use some of the longer formats that you already mention in your question.

C # and VB languages ​​do not always have equivalent functions.

+3
source
 If obj is bitmap Then Dim bmp = obj 

or

 Dim bmp = If(obj is bitmap, obj, Nothing) 

Not exactly pattern matching in itself, but it does the same.

Could you do it this way in C #:

 var bmp = obj is bitmap ? obj : nothing; 
0
source

Source: https://habr.com/ru/post/1273661/


All Articles