Wrox Programmer Forums
|
BOOK: Professional .NET 2.0 Generics
This is the forum to discuss the Wrox book Professional .NET 2.0 Generics by Tod Golding; ISBN: 9780764559884
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional .NET 2.0 Generics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 20th, 2011, 04:52 PM
Authorized User
 
Join Date: Aug 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generic collection works but has quirks

This test collection uses what could be called an "inner list." One quirk is that the ADD uses the InsertItem routine in the test class instead of the default (internal) .Add shown by debugging. INSERT uses the class InsertItem as expected. But INDEXOF does not use the class IndexOf and it returns -1 even though the "December" item is in the collection.
Public Class WinterMonth
Private _monthOf As String
Public Property MonthOf() As String
Get
Return _monthOf
End Get
Set (ByVal value as String)
_monthOf = value
End Set
End Property
Public Sub New(ByVal monthOf As String)
Me.MonthOf = monthOf
End Sub
End Class
Public Class WinterMonths(Of T)
Inherits Collection(Of T)
Protected Overrides Sub InsertItem(ByVal index As Integer, ByVal item As T)
MyBase.InsertItem(index,item)
End Sub
Protected Overloads Sub IndexOf(ByVal item as T)
MyBase.IndexOf(item)
End Sub
End Class
Protected Sub Page_Load etc.
Dim winter As New WinterMonths(Of WinterMonth)
winter.Add(New WinterMonth("January"))
winter.Insert(0, New WinterMonth("December"))
winter.Add(New WinterMonth("February"))
winter.Insert(winter.Count, New WinterMonth("March"))
Dim idx = winter.IndexOf(New WinterMonth("December"))
monthlist.DataSource = winter
monthlist.DataValueField = "MonthOf"
monthlist.DataBind()
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2, system.collection.generic.list Ziaulhassan BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 2 January 2nd, 2010 03:51 AM
How can i make this generic girija45701 C# 0 November 29th, 2008 04:32 AM
Databinding a Generic Collection to a Datagrid rolandatem ASP.NET 2.0 Professional 0 October 7th, 2006 11:08 PM
Generic collection population from database micmit C# 2005 7 September 19th, 2006 05:53 AM
DateTime format quirks ADMystery ASP.NET 1.0 and 1.1 Professional 5 September 18th, 2006 06:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.