本文整理汇总了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