本文整理汇总了VB.NET中System.ArrayTypeMismatchException类的典型用法代码示例。如果您正苦于以下问题:VB.NET ArrayTypeMismatchException类的具体用法?VB.NET ArrayTypeMismatchException怎么用?VB.NET ArrayTypeMismatchException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayTypeMismatchException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Main
Option Explicit On
Option Strict On
Namespace ArrayTypeMismatch
Class Class1
Public Shared Sub Main(ByVal args() As String)
Dim names As String() = {"Dog", "Cat", "Fish"}
Dim objs As System.Object() = CType(names, System.Object())
Try
objs(2) = "Mouse"
Dim animalName As Object
For Each animalName In objs
System.Console.WriteLine(animalName)
Next animalName
Catch exp As System.ArrayTypeMismatchException
' Not reached, "Mouse" is of the correct type.
System.Console.WriteLine("Exception Thrown.")
End Try
Try
Dim obj As System.Object
obj = CType(13, System.Object)
objs(2) = obj
Catch exp As System.ArrayTypeMismatchException
' Always reached, 13 is not a string.
System.Console.WriteLine("New element is not of the correct type.")
End Try
' Set objs to an array of objects instead of an array of strings.
Dim objs2(3) As System.Object
Try
objs2(0) = "Turtle"
objs2(1) = 12
objs2(2) = 2.341
Dim element As Object
For Each element In objs2
System.Console.WriteLine(element)
Next element
Catch exp As System.ArrayTypeMismatchException
' ArrayTypeMismatchException is not thrown this time.
System.Console.WriteLine("Exception Thrown.")
End Try
End Sub
End Class
End Namespace
开发者ID:VB.NET开发者,项目名称:System,代码行数:52,代码来源:ArrayTypeMismatchException
注:本文中的System.ArrayTypeMismatchException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论