VB.NET等效于C#7类型模式匹配

编程入门 行业动态 更新时间:2024-10-23 11:21:01
本文介绍了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类型模式匹配

本文发布于:2023-11-03 15:45:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555484.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   模式   VB   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!