VB.Net/Language Basics/Variable Scope — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 16:40, 26 мая 2010
Block scope variable X
Imports System
public class MainClass
Shared Sub Main()
Dim Counter As Short
For Counter = 1 To 3
If True Then " Always enter this block
Dim X As Short
Console.WriteLine(X)
X = Counter
End If
Next Counter
End Sub
End Class
Variable Scope Demo
Imports System
Public Class MainClass
Shared Sub Main(ByVal args As String())
DisplayAAAName()
DisplayBBBName()
End Sub
Shared Sub DisplayAAAName()
Dim myName As String
myName = "AAA"
Console.WriteLine(myName, "Scope Demo")
End Sub
Shared Sub DisplayBBBName()
Dim myName As String
myName = "BBB"
Console.WriteLine(myName, "Scope Demo")
End Sub
End Class
Variable Scope: Function
Imports System
Imports System.Diagnostics
Public Class MainClass
Shared Sub Main()
For i As Integer = 1 To 5
Dim j As Integer = 3
If i = j Then
Dim M As Integer = i + j
Console.WriteLine("M: " & M)
Else
Dim N As Integer = i * j
Console.WriteLine("N: " & N)
End If
Dim k As Integer = 123
Console.WriteLine("k: " & k)
Next i
End Sub
End Class