本文整理匯總了VB.NET中System.Diagnostics.Contracts.Contract.ForAll方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Contract.ForAll方法的具體用法?VB.NET Contract.ForAll怎麽用?VB.NET Contract.ForAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了Contract.ForAll方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Program
' 導入命名空間
Imports System.Diagnostics.Contracts
Imports System.Collections.Generic
Class Program
' Start application with at least two arguments.
Shared Sub Main(ByVal args() As String)
args(1) = Nothing
Contract.Requires(Not (args Is Nothing) AndAlso Contract.ForAll(args, Function(s) s Is Nothing))
' test the ForAll method. This is only for purpose of demonstrating how ForAll works.
CheckIndexes(args)
Dim numbers As New Stack(Of String)
numbers.Push("one")
numbers.Push("two")
numbers.Push("three")
numbers.Push("four")
numbers.Push("five")
Contract.Requires(Not (numbers Is Nothing) AndAlso Not Contract.ForAll(numbers, Function(s) s Is Nothing))
' test the ForAll generic overload. This is only for purpose of demonstrating how ForAll works.
CheckTypeArray(numbers)
End Sub
Private Shared Function CheckIndexes(ByVal args() As String) As Boolean
Try
If Not (args Is Nothing) AndAlso Not Contract.ForAll(0, args.Length, Function(i) args(i) Is Nothing) Then
Throw New ArgumentException("The parameter array has a null element", "args")
End If
Return True
Catch e As ArgumentException
Console.WriteLine(e.Message)
Return False
End Try
End Function 'CheckIndexes
Private Shared Function CheckTypeArray(ByVal xs As Stack(Of String)) As Boolean
Try
If Not (xs Is Nothing) AndAlso Not Contract.ForAll(xs, Function(s) s Is Nothing) Then
Throw New ArgumentException("The parameter array has a null element", "Stack")
End If
Return True
Catch e As ArgumentException
Console.WriteLine(e.Message)
Return False
End Try
End Function 'CheckTypeArray
End Class