Partial Class TimeDisplay
Inherits System.Web.UI.UserControl
Private Sub Page_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
RefreshTime()
End If
End Sub
Public Sub RefreshTime()
If strFormat = String.Empty Then
lnkTime.Text = DateTime.Now.ToLongTimeString()
Else
lnkTime.Text = DateTime.Now.ToString(Format)
End If
End Sub
Protected Sub lnkTime_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkTime.Click
RefreshTime()
End Sub
Private strFormat As String
Public Property Format() As String
Get
Return strFormat
End Get
Set(ByVal value As String)
strFormat = value
End Set
End Property
End Class
Console.WriteLine("***** Custom Generic Collection *****")
Console.WriteLine()
'make a collection of Cars
Dim myCars As New CarCollection(Of Car)()
myCars(0) = New Car("Rusty", 20)
myCars(1) = New Car("Zippy", 90)
For Each c As Car In myCars
Console.WriteLine("PetName: {0}, Speed: {1}", c.petName, c.Speed)
Next
Console.ReadLine()
Public Class CarCollection(Of T)
Implements IEnumerable(Of T)
Private myCars As New List(Of T)
'generic default property
Default Public Property Item(ByVal index As Integer) As T
Get
Return myCars(index)
End Get
Set(ByVal value As T)
myCars.Add(value)
End Set
End Property
Public Sub ClearCars()
myCars.Clear()
End Sub
Public Function CarCount() As Integer
Return myCars.Count()
End Function
Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of T) Implements System.Collections.Generic.IEnumerable(Of T).GetEnumerator
Return myCars.GetEnumerator()
End Function
Public Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
Return myCars.GetEnumerator()
End Function
End Class
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment