本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System.Diagnostics.Contracts,代码行数:56,代码来源:Contract.ForAll
注:本文中的System.Diagnostics.Contracts.Contract.ForAll方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论