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
Console.WriteLine(obj(x).Name)
End If
Next
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)
MyBase.New()
MyClasses.Add(Me)
Name = myname
End Sub
Default Public ReadOnly Property OtherMyClassObjects(ByVal idx As Integer) As MyClass
Get
Return CType(MyClasses.Item(idx), MyClass)
End Get
End Property
Public Shared ReadOnly Property OtherObjectCount() As Integer
Get
Return myclasses.Count
End Get
End Property
Public ReadOnly Property MyIndex() As Integer
Get
Return myclasses.IndexOf(Me)
End Get
End Property
Public Sub Dispose() Implements IDisposable.Dispose
MyClasses.Remove(Me)
End Sub
End Class
|