Vb. NET Module Summary (ii)

Source: Internet
Author: User

' Code in the Module1.vb file:

Module Mainclas
Sub Main ()

Dim Thefirstinstanceoftestscope as New testscope
Thefirstinstanceoftestscope.testscopesubmethodone ()
Dim aStr as String = Thefirstinstanceoftestscope.testscopefunctiongmethodone ()
Console.WriteLine (ASTR)

Dim Thefirstinstanceofouttestscope as New outtestscope ()
' Ibid function, instantiate Outtestscope class
' Dim Thefirstinstanceofouttestscope as Outtestscope
' Thefirstinstanceofouttestscope = New outtestscope ()
' Ibid function, instantiate Outtestscope class
' Dim thefirstinstanceofouttestscope = New outtestscope ()
Thefirstinstanceofouttestscope.outtestscopesubmethodone ()
Dim aastr as String = Thefirstinstanceofouttestscope.outtestscopefunctiongmethodone ()
Console.WriteLine (AASTR)
Console.WriteLine (thefirstinstanceofouttestscope.cc)

Thefirstinstanceoftestscope.diaoyongmmethod () ' Ways to invoke other modules through instances of a class
Dim mtwoclassfiled as New mtwoclass
Mtwoclassfiled.mtwoclassmethod () module directly calls methods in classes of other modules
Console.WriteLine (Mthreemethod ()) ' module directly calls other modules ' methods
Console.ReadLine ()

End Sub
End Module


Class Testscope
Dim A as String
Private B as String
Public C as String
Sub New () ' No parameter constructor
Me. A = "Dim_a"
Me. B = "Private_b"
Me. C = "Public_c"
End Sub
' Public Static Sub Testscopemethodone () ' cannot declare a sub method (or Sub procedure) with Static, prompting an error: Method cannot be declared "Static"
Public Sub Testscopesubmethodone ()
Console.WriteLine (String. Format ("Testscopesubmethodone (): {0} {1} {2}", A, B, c))
End Sub
The ' Public Static function Testscopefunctiongmethodone () as String ' cannot declare a function method (or function functions) with Static, prompting an error: The method cannot be declared as " Static "
Public Function Testscopefunctiongmethodone () as String
Return String. Format ("Testscopefunctiongmethodone (): {0} {1} {2}", A, B, c)
End Function
Public Sub Diaoyongmmethod ()
' Mtwomethod ()
Console.WriteLine (Mthreemethod ())
End Sub
End Class

Module Mtwo
' Public Sub Mtwomethod ()
Private mtwofiled as String = "mtwofiled"
Methods in private Sub Mtwomethod () modules can be decorated with private, but can only be used in the current module and cannot be used in other modules
Console.WriteLine (mtwofiled)
End Sub
Class Mtwoclass
Sub Mtwoclassmethod ()
Mtwomethod ()
End Sub
End Class
End Module

Module Mthree
Private Sub Mprivatethreemethod ()
Console.WriteLine ("Mprivatethreemethod ()")
End Sub
' Public Function Mthreemethod () as String
Function Mthreemethod () as String ' The method in the module is shared by the hermit and can be accessed outside of the module, plus no public.
Mprivatethreemethod ()
Return "Mthreemethod ()"
End Function
End Module

' You cannot use static to declare methods (sub and function) in vb.net, and you cannot declare member variables, only to declare static variables in methods (sub and function).
' Shared can be used to declare a variable or to declare a method, or to declare a member variable, which is just the opposite of static.
' Shared in Vb.ne is more like a static role in C #. The member variables (fields) and methods (sub and function) declared in vb.net with shared declarations can only be accessed using the class name, not with instances of the class

' Multiple modules can be defined in a file
' You can define a class in another file like C # that uses the same usage as the classes defined in a file (parcel fields, methods, properties, and so on)

' The methods in the module are shared by the hermit and can be accessed directly from outside the module (other modules, classes, structures, etc.), plus no public.
' The methods in the module cannot be declared as protected,shared and static, only public (default is public) and private.
' But the methods of classes (or structs) in a module can be declared as public,private,protected and shared.



' Code in the Outtestscope.vb file:

Public Class Outtestscope
Dim AA as String
Private BB as String
Public CC as String
Sub New () ' No parameter constructor
Me. AA = "Dim_aa"
Me. bb = "PRIVATE_BB"
Me. cc = "PUBLIC_CC"
End Sub
' Public Static Sub Testscopemethodone () ' cannot declare a sub method (or Sub procedure) with Static, prompting an error: Method cannot be declared "Static"
Public Sub Outtestscopesubmethodone ()
Console.WriteLine (String. Format ("Outtestscopesubmethodone (): {0} {1} {2}", AA, BB, cc))
End Sub
The ' Public Static function Testscopefunctiongmethodone () as String ' cannot declare a function method (or function functions) with Static, prompting an error: The method cannot be declared as " Static "
Public Function Outtestscopefunctiongmethodone () as String
Return String. Format ("Outtestscopefunctiongmethodone (): {0} {1} {2}", AA, BB, cc)
End Function
End Class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.