最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

VB.NET 中标识符周围的方括号表示什么?

网站源码admin37浏览0评论
本文介绍了VB.NET 中标识符周围的方括号表示什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

总的来说,我对 VB 和 .NET 非常熟悉,但我只是遇到了这段代码:

I'm quite familiar with VB and .NET in general, but I just ran across this code:

Me.[GetType]()

GetType 括号的用途是什么?

推荐答案

方括号用于告诉编译器他应该将它解释为一个类型,即使它是一个关键字.但是您的示例应该与 Me.GetType() 相同.

The square brackets are used to tell the compiler that he should interpret it as a type, even if it would be a keyword. But your example should be the same as Me.GetType().

例如,您可以将它用于枚举.

You could use it for example for Enums.

示例枚举:

Enum Colors
    Red
    Green
    Blue
    Yellow
End Enum 'Colors

Dim colors = [Enum].GetValues(GetType(Colors))
For Each c In colors
   Console.WriteLine(c)
Next

那不会正常编译:

Enum.GetValues(GetType(Colors)) 'because Enum is a keyword'

这篇关于VB.NET 中标识符周围的方括号表示什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

发布评论

评论列表(0)

  1. 暂无评论