Scope rules and instance variables : Instance Variables « Class « VB.Net

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
VB.Net » Class » Instance VariablesScreenshots 
Scope rules and instance variables
Scope rules and instance variables

Imports System

Public Class MainClass
   ' instance variable can be used anywhere in class
   Shared Dim value As Integer = 1

    Shared Sub Main(ByVal args As String())
      ' variable local to FrmScoping_Load hides instance variable
      Dim value As Integer = 5

      Console.WriteLine"local variable value in" & _
         " FrmScoping_Load is " & value )

      MethodA() ' MethodA has automatic local value
      MethodB() ' MethodB uses instance variable value
      MethodA() ' MethodA creates new automatic local value
      MethodB() ' instance variable value retains its value

      Console.WriteLinevbCrLf & vbCrLf & "local variable " & _
         "value in FrmScoping_Load is " & value )

    End Sub

   ' automatic local variable value hides instance variable
   Shared Sub MethodA()
      Dim value As Integer = 25 ' initialized after each call

      Console.WriteLinevbCrLf & vbCrLf & "local variable " & _
         "value in MethodA is " & value & " after entering MethodA" )
      value += 1
      Console.WriteLinevbCrLf & "local variable " & _
         "value in MethodA is " & value & " before exiting MethodA" )
   End Sub ' MethodA

   ' uses instance variable value
   Shared Sub MethodB()
      Console.WriteLinevbCrLf & vbCrLf & "instance variable" & _
         " value is " & value & " after entering MethodB" )
      value *= 10
      Console.WriteLinevbCrLf & "instance variable " & _
         "value is " & value & " before exiting MethodB" )
   End Sub ' MethodB

End Class

           
       
Related examples in the same category
w___w_w___.___j__a__v___a__2_s_.___co___m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.