In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to share VB.NET, which is very detailed and has certain reference value. Friends who are interested must finish reading it!
VB.NET sharing method
We have a better change in VB.NET. Not only can a class have all the normal methods and properties that can be implemented by creating instances of the class, but they can also have methods that do not need to create instances of the class. these methods are the shared methods that will be introduced in this tutorial. These methods are also called static or class methods in other programming languages.
A shared method cannot be accessed as an ordinary method through an instance of an object, but can be accessed directly from the class. Here is a simple example of a sharing method:
Public Class Math Shared Function Add (ByVal an As Integer, ByVal b As Integer) As Integer Return a + b End Function End Class
We can access it without instantiating a Math object, as shown in the following code:
Dim result As Integer result = Math.Add (5,10)
Now take a closer look, instead of using a variable, we use the method of the class directly. Using the usual method will lead to an error, but using the sharing method makes everything acceptable. Shared methods can not only be accessed by the usual methods, but also provide access without creating an object. In fact, when a shared method is called, no objects are created, just like a program in a module can be called directly.
VB.NET shared sharing methods can be overloaded like other common methods, so you can use the same shared methods to create a series of variable methods, each with a different parameter list. The default scope for shared methods is Public. We can also set the shared method to Friend, Protected, or Private in the declaration. In fact, when overloading a method, we have a different scope as long as the parameter list is different.
Let's take a look at an example of how the sharing method is used. When we want to open a text file for input, we can use a shared code in the File class, as follows:
Dim infile As StreamReader = File.OpenText (words.txt) Dim strIn As String str = infile.ReadLine ()
No files of any type have been created here. The OpenText method is a shared method that opens a file and returns a StreamReader object. Another example comes from the System.Guid data type. This class describes a global and unique user ID (GUID) value, but we can create a new method through a shared method.
Dim guidID As Guid () guidID = Guid.NewGuid ()
This NewGuid method is called directly from the Guid class. It creates a new Guid object and returns a numeric value.
The above is all the content of this article "how to share methods with VB.NET". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.