Searchable Indexer : Indexer « Class Module « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Class Module » Indexer 
6.27.2.Searchable Indexer
Option Strict On
 Imports System

 Public Class MyArray
     Private strings(255As String
     Private ctr As Integer = 0

     Public Sub New(ByVal ParamArray initialStrings() As String)
         Dim As String
         For Each s In initialStrings
             strings(ctr= s
             ctr += 1
         Next
     End Sub
     Public Sub Add(ByVal theString As String)
         If ctr >= strings.Length Then
         Else
             strings(ctr= theString
             ctr += 1
         End If
     End Sub

     Default Public Property Item_
        ByVal index As IntegerAs String
         Get
             If index < Or index >= strings.Length Then
             Else
                 Return strings(index)
             End If
         End Get
         Set(ByVal Value As String)
             If index >= ctr Then
             Else
                 strings(index= Value
             End If
         End Set
     End Property

     Default Public Property Item_
        ByVal index As StringAs String
         Get
             If index.Length = Then
             Else
                 Return strings(findString(index))
             End If
         End Get
         Set(ByVal Value As String)
             strings(findString(index)) = Value
         End Set
     End Property

     Private Function findString_
        ByVal searchString As StringAs Integer
         Dim As Integer
         For i = To strings.Length - 1
             If strings(i).StartsWith(searchStringThen
                 Return i
             End If
         Next
         Return -1
     End Function

     Public Function Count() As Integer
         Return ctr
     End Function
 End Class

 Public Class Tester

     Public Sub Run()
     End Sub

     Public Shared Sub Main()
         Dim lbt As New MyArray("Hello""World")
         Dim As Integer

         Console.WriteLine("After creation...")
         For i = To lbt.Count - 1
             Console.WriteLine("lbt({0}): {1}", i, lbt(i))
         Next

         ' add a few strings
         lbt.Add("W")
         lbt.Add("s")
         lbt.Add("n")
         lbt.Add("t")

         Console.WriteLine(vbCrLf & "After adding strings...")
         For i = To lbt.Count - 1
             Console.WriteLine("lbt({0}): {1}", i, lbt(i))
         Next

         Dim subst As String = "e"
         lbt(1= subst
         lbt("H""GoodBye"

         Console.WriteLine(vbCrLf & "After editing strings...")
         For i = To lbt.Count - 1
             Console.WriteLine("lbt({0}): {1}", i, lbt(i))
         Next
     End Sub
 End Class
After creation...
lbt(0): Hello
lbt(1): World

After adding strings...
lbt(0): Hello
lbt(1): World
lbt(2): W
lbt(3): s
lbt(4): n
lbt(5): t

After editing strings...
lbt(0): GoodBye
lbt(1): e
lbt(2): W
lbt(3): s
lbt(4): n
lbt(5): t
6.27.Indexer
6.27.1.Define Indexer for your own class
6.27.2.Searchable Indexer
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.