ARTICLE

INDEXER in VB

Posted by Senthurganesh Ramkumar Articles | Visual Basic 2010 April 16, 2008
Through this article you will learn the concept of INDEXER in VB.
 
Reader Level:

INDEXER IN VB

 

In vb introduce new concept is Indexer. This is very useful for some situation. Let as discuss something about Indexer.

  • Indexer Concept is object act as an array.
  • Indexer an object to be indexed in the same way as an array.
  • Indexer modifier can be private, public, protected or internal.
  • The return type can be any valid vb types.
  • Indexers in vb must have at least one parameter. Else the compiler will generate a compilation error.

this [Parameter]

{

    get

    {

        // Get codes goes here

    }

    set

    {

        // Set codes goes here

    }

} 

 

For Example:

 

Imports System 

Imports System.Collections.Generic 

Imports System.Text
 

Namespace Indexers
 

    Class ParentClass 

        Private range As String() = New String(4) {}

        Default Public Property Item(ByVal indexrange As Integer) As String 

            Get 

                Return range(indexrange)

            End Get 

            Set(ByVal value As String

                range(indexrange) = value

            End Set

        End Property 

    End Class
 

    ' The Above Class just act as array declaration using this pointer 
 

    Class childclass 

        Public Shared Sub Main()

            Dim obj As New ParentClass()
 

            ' The Above Class ParentClass create one object name is obj 
 

            obj(0) = "ONE"

            obj(1) = "TWO" 

            obj(2) = "THREE" 

            obj(3) = "FOUR" 

            obj(4) = "FIVE" 

            Console.WriteLine("WELCOME TO C# CORNER HOME PAGE" & Chr(10) & ""

            Console.WriteLine("" & Chr(10) & ""

            Console.WriteLine("{0}" & Chr(10) & ",{1}" & Chr(10) & ",{2}" & Chr(10) & ",{3}" & Chr(10) & ",{4}" & Chr(10) & "", obj(0), obj(1), obj(2), obj(3), obj(4))

            Console.WriteLine("" & Chr(10) & ""

            Console.WriteLine("ALS.Senthur Ganesh Ram Kumar" & Chr(10) & ""

            Console.WriteLine("" & Chr(10) & ""

            Console.ReadLine() 

        End Sub 

    End Class 

End Namespace

NOTE: THIS ARTICLE IS CONVERTED FROM C# TO VB.NET USING A CONVERSION TOOL. ORIGINAL ARTICLE CAN BE FOUND ON C# Corner (http://www.c-sharpcorner.com/).

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Diagram
Become a Sponsor