ASP custom arraylist class

Source: Internet
Author: User
Arrays are the most commonly used in encoding, but unfortunately they do not have a variable length array structure. We can see that C # has an arraylist, so we thought about it and encapsulated it with ASP, the main purpose is to use "redim preserve" to redefine the array size. The following is my code: program code <%
'Written by shaoyun site: www.devjs.com
Class arraylist
Private m_array ()
Private m_count
Private sub class_initialize ()
Redim m_array (0)
M_count = 0
End sub
Private sub class_terminate ()
Redim m_array (0)
M_count = 0
End sub
Public property get count ()
Count = m_count
End Property
Public property get item (INDEX)
Item = m_array (INDEX)
End Property
Public Function add (arritem)
Redim preserve m_array (m_count)
M_array (m_count) = arritem
M_count = m_count + 1
End Function
End Class
%>

The procedure is as follows: program code <%
Dim arr: Set arr = new arraylist
Arr. Add "A": arr. Add "B": arr. Add "C"
Response. Write arr. Count & "<br>"
For I = 0 to ARR. Count-1
Response. Write arr. Item (I) & "<br>"
Next
Set arr = nothing
%>

It is very simple. There is only one public function and two read-only attributes, but it is very practical!

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.