Define and use Properties: ReadOnly : ReadOnly « Class « VB.Net

Define and use Properties: ReadOnly

Imports System
Imports System.Collections

public class MainClass
   Shared Sub Main()
        Dim obj As New MyOwnClass("Firstobject")

        Dim x As Integer
        Console.WriteLine("This object is: " & obj.Name)
        Console.WriteLine("Other objects are: ")
        For x = 0 To MyOwnClass.OtherObjectCount - 1
            If x <> obj.MyIndex Then
            End If

   End Sub

End Class

    Class MyOwnClass
        Implements IDisposable

        Private Shared myclasses As New ArrayList()

        Public Name As String

        Public Sub New(ByVal myname As String)
            Name = myname
        End Sub

        Default Public ReadOnly Property OtherMyClassObjects(ByVal idx As Integer) As MyClass
                Return CType(MyClasses.Item(idx), MyClass)
            End Get
        End Property

        Public Shared ReadOnly Property OtherObjectCount() As Integer
                Return myclasses.Count
            End Get
        End Property

        Public ReadOnly Property MyIndex() As Integer
                Return myclasses.IndexOf(Me)
            End Get
        End Property

        Public Sub Dispose() Implements IDisposable.Dispose
        End Sub
    End Class


Related examples in the same category

1.Define and use ReadOnly Class PropertyDefine and use ReadOnly Class Property
2.Define ReadOnly PropertyDefine ReadOnly Property
3.Demo Const and ReadOnlyDemo Const and ReadOnly