In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces VB.NET List (T) how to write the framework, the article introduces in great detail, has a certain reference value, interested friends must read it!
To use VB.NET List (T), we need to understand how to deploy the various methods provided by the .NET Framework. This will also be the content of this article. I've written three examples-- using ForEach, FindAll, and Sort-- to illustrate how the same list class works.
The * step is to create a sharing list. You can get data from many ways, but the easiest way is to add. In the text, we will write code to classify the sets in the example. So, let's talk about the code that creates the set.
First, I need a Bottle object that represents the set. The code written for this is fully standard, and in fact, VB.NET 2008 Express Intellisense will write most of the code for you. The following is my partner:
Public Class Bottle "internalProperties" Public Property Brand () As String Public Property Name () As Strin Public Property Category () As String Public Property Size () As Decimal Public Sub New (_ End Sub End Class
All of this is standard code in VB.NET1.0. However, you need to specify it by defining our own Bottle object. We will benefit from multiple types in the same set.
Next we will introduce the ForEach, FindAll, and Sort methods.
When we use these methods, we will find the fun. First, let's deploy the ForEach method. The Microsoft file contains the syntax definition of its use.
Dim instance As List Dim action As Action (Of T) instance.ForEach (action)
Microsoft further defines delegation behavior as a way to demonstrate the behavior passed by an object. The current VB.NET List (T) elements are transferred separately to the Action (T) representation.
The only thing to do is to write code for the delegated method. The misunderstanding of this key point is the reason why most people are confused about VB.NET. This feature or subroutine is the place where all custom coding for objects of type Of is done. When we can use this feature correctly, the process is very simple. In our example, the use of it is simple. The entire example of Bottle is passed, and the subroutine picks out any data it needs.
Sub displayBottle (ByVal b As Bottle) Console.WriteLine (b.Brand & "-" & b.Name) End Sub
FindAll is a little more complicated. Microsoft's explanation of FindAll is as follows:
Dim instance As List Dim match As Predicate (Of T) Dim returnValue As List (Of T) returnValue = instance.FindAll (match)
This represents a defined set of standards and a way to determine whether a specified object conforms to those standards. In other words, we can create any code that can find data in the list. The Predicate (Of T) I wrote can search for Beer categories:
Function findBeer (ByVal b As Bottle) _ As Boolean If (b.Category = "Beer") Then Return Tru Else Return False End If End Function
FindAll returns the entire VB.NET List (T) rather than the representative code for each item in the call list. This VB.NET List (T) contains only data that matches Predicate (T). The definition and operation of the second VB.NET List (T) also depends on the code we write. I repeat, my code is simplified to avoid redundancy.
Dim sublist As List (Of Bottle) sublist = Cabinet.FindAll (AddressOf findBeer) For Each result As Bottle In sublist Console.WriteLine (result.Brand & "-" & result.Name) Next
One of the methods discussed in this article is Sort. Microsoft uses terms that you may not be familiar with to explain it. There are actually four different Sort method payloads:
Sort () Sort (Icomparer (T) Sort (Comparison) Sort (Int32,Int32,Icomparer (T))
This allows us to write our own code using the Sort methods defined in the .NET Framework or simply collect part of the collection by using the starting position and count parameters.
In this example, I wrote another representative for my comparator. Since I want to classify through my classification method, I just extract the value of each instance in the Bottle object that is passed.
Private Shared Function sortCabinet (_ ByVal x As Bottle, ByVal y As Bottle)
As Integer Return x.Category.CompareTo (y.Category)
End Function
These methods are selected to illustrate the main ways of writing framework method code in VB.NET List (T). You will find that they make VB.NET List (T) more useful.
These are all the contents of the article "how to write frameworks for VB.NET List (T)". 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.