首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >VB.NET的隐藏功能?

VB.NET的隐藏功能?
EN

Stack Overflow用户
提问于 2017-12-27 03:24:50
回答 3查看 0关注 0票数 0

我学到了不少浏览C#的隐藏特征当我在VB.NET上找不到类似的东西时,我感到很惊讶。

那么,它的一些隐藏的或不太为人所知的特征是什么?

EN

回答 3

Stack Overflow用户

发布于 2017-12-27 10:26:26

Exception When子句在很大程度上是未知的。

考虑到这一点:

代码语言:javascript
复制
Public Sub Login(host as string, user as String, password as string, _
                            Optional bRetry as Boolean = False)
Try
   ssh.Connect(host, user, password)
Catch ex as TimeoutException When Not bRetry
   ''//Try again, but only once.
   Login(host, user, password, True)
Catch ex as TimeoutException
   ''//Log exception
End Try
End Sub
票数 0
EN

Stack Overflow用户

发布于 2017-12-27 11:27:17

Custom Enums

一个真实的隐秘VB的特性是completionlistXML文档标记,可用于创建自己的Enum-具有扩展功能的类类型。不过,这个特性在C#中不起作用。

我最近的一个法典中的一个例子:

代码语言:javascript
复制
'
''' <completionlist cref="RuleTemplates"/>
Public Class Rule
    Private ReadOnly m_Expression As String
    Private ReadOnly m_Options As RegexOptions

    Public Sub New(ByVal expression As String)
        Me.New(expression, RegexOptions.None)
    End Sub

    Public Sub New(ByVal expression As String, ByVal options As RegexOptions)
        m_Expression = expression
        m_options = options
    End Sub

    Public ReadOnly Property Expression() As String
        Get
            Return m_Expression
        End Get
    End Property

    Public ReadOnly Property Options() As RegexOptions
        Get
            Return m_Options
        End Get
    End Property
End Class

Public NotInheritable Class RuleTemplates
    Public Shared ReadOnly Whitespace As New Rule("\s+")
    Public Shared ReadOnly Identifier As New Rule("\w+")
    Public Shared ReadOnly [String] As New Rule("""([^""]|"""")*""")
End Class

现在,当将值赋值给声明为Rule,IDE提供了一个IntelliSense列表,其中列出了RuleTemplates...

编辑:

由于这是一个依赖于IDE的特性,所以很难在使用它时显示它的外观,但我只使用屏幕截图:

行动中的完成列表http://page.mi.fu-berlin.de/kRudolph/Stuff/Completionlist.png

实际上,IntelliSense与使用Enum...

票数 0
EN

Stack Overflow用户

发布于 2017-12-27 12:31:35

你注意到类似的比较操作符了吗?

代码语言:txt
复制
 `Dim b As Boolean = "file.txt" Like "*.txt"` 

更多来自MSDN

代码语言:javascript
复制
Dim testCheck As Boolean

' The following statement returns True (does "F" satisfy "F"?)'
testCheck = "F" Like "F"

' The following statement returns False for Option Compare Binary'
'    and True for Option Compare Text (does "F" satisfy "f"?)'
testCheck = "F" Like "f"

' The following statement returns False (does "F" satisfy "FFF"?)'
testCheck = "F" Like "FFF"

' The following statement returns True (does "aBBBa" have an "a" at the'
'    beginning, an "a" at the end, and any number of characters in '
'    between?)'
testCheck = "aBBBa" Like "a*a"

' The following statement returns True (does "F" occur in the set of'
'    characters from "A" through "Z"?)'
testCheck = "F" Like "[A-Z]"

' The following statement returns False (does "F" NOT occur in the '
'    set of characters from "A" through "Z"?)'
testCheck = "F" Like "[!A-Z]"

' The following statement returns True (does "a2a" begin and end with'
'    an "a" and have any single-digit number in between?)'
testCheck = "a2a" Like "a#a"

' The following statement returns True (does "aM5b" begin with an "a",'
'    followed by any character from the set "L" through "P", followed'
'    by any single-digit number, and end with any character NOT in'
'    the character set "c" through "e"?)'
testCheck = "aM5b" Like "a[L-P]#[!c-e]"

' The following statement returns True (does "BAT123khg" begin with a'
'    "B", followed by any single character, followed by a "T", and end'
'    with zero or more characters of any type?)'
testCheck = "BAT123khg" Like "B?T*"

' The following statement returns False (does "CAT123khg" begin with'
'    a "B", followed by any single character, followed by a "T", and'
'    end with zero or more characters of any type?)'
testCheck = "CAT123khg" Like "B?T*"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100000035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档