VB.Net Tutorial/Development/DirectCast
Версия от 16:40, 26 мая 2010; (обсуждение)
DirectCast
public class Test
public Shared Sub Main
Dim numberOfTimes As Object
numberOfTimes = 12
If TypeOf numberOfTimes Is Integer Then
Dim repeatCount As Integer
repeatCount = _
DirectCast(numberOfTimes, Integer)
For idx As Integer = 1 To repeatCount
Console.WriteLine("Duncanma")
Next
End If
End Sub
End class
Duncanma Duncanma Duncanma Duncanma Duncanma Duncanma Duncanma Duncanma Duncanma Duncanma Duncanma Duncanma
DirectCast from Integer to MsgBoxResult
Option Strict On
Public Module TestDirectCast
Public Sub Main
Dim choice As Integer = MsgBox("Continue?", MsgBoxStyle.YesNo)
Dim result As MsgBoxResult = DirectCast(choice, MsgBoxResult)
Console.WriteLine(result.ToString)
End Sub
End Module
No