frmfalsepositives.vb

来自「Microsoft Mobile Development Handbook的代码」· VB 代码 · 共 46 行

VB
46
字号
Public Class frmFalsePositives

  Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
    Dim i As Int32
    Dim b As Boolean = True
    Try
      i = Int32.MaxValue
      i += 1
    Catch ex As Exception When b = False
      MsgBox("caught")
      Return
    End Try

    MsgBox("not caught")
  End Sub

  Public Sub FalsePositive1()
    Dim s As String
    s = s & "why?" ' WARNING ?! - it is a valid statement
  End Sub
  Public Sub FalsePositive2()
    Dim o As Collection

    ' some other code here

    If o Is Nothing Then  ' WARNING ?! - just checking if it is null
      o = New Collection()
    End If
  End Sub

  Public Sub FalsePositive3()
    Dim s As Object
    Me.ReturnsValueByRef(s) ' WARNING ?! - I don't want to initialise s. The function will
  End Sub

  Public Function MaybeReturnNothingOrSomething() As Collection
    Return Nothing
  End Function

  ' if only VB had "out" like C# has
  Private Function ReturnsValueByRef(ByRef theMethodAssignsThis As Object) As Boolean
    theMethodAssignsThis = "some value to return"
    Return True
  End Function
End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?