Implement Sort and Custom Enumerator in Generic List
page 1 of 7
Published: 24 Sep 2007
Abstract
The introduction of C# 2.0 gave many new features that made developers' lives easier. This article elaborates on the usage of the Genric list as an alternative for business object collection and explains the implementation of sorting and custom enumerations with generic list. Developers can implement their own sorting and custom enumerator for the generic list using this article.
by Satheesh Babu
Feedback
Average Rating: 
Views (Total / Last 10 Days): 40802/ 68

Introduction

It is obvious that when we are designing business object or Entities for our application we will create its corresponding collections. In 1.x days we used ArrayList for creating a collection of object or entity. We can also create our own custom collection by inheriting the Arraylist or CollectionBase in those times. The main disadvantage of using ArrayList is that it can hold any type, which can cause some serious issue where a collection of similar objects are expected. This is the right place in 1.x to go for our own collection by inheriting the Arraylist or CollectionBase.

With the introduction of 2.0 Framework we got so many new useful features that make our development easy in our applications. Generic list is one of such feature which we can use for creating a collection of similar objects. We can create our collection with generic List<T>, where T can be our BO, which can be strongly typed. For example, List<Employee> will allow only Employee instance to be added to the list. Moving forward we will see how to implement sort to using generic list Sort overload methods and also we will implement a custom enumerator that iterates through the list with the use of yield keyword.


View Entire Article

User Comments

Title: Comment box creation   
Name: Raghav
Date: 2011-11-01 1:43:04 PM
Comment:
I want to develop a comment box like face book in my website using ASP.net
Title: Mr   
Name: Banx
Date: 2010-10-06 6:59:59 PM
Comment:
With overload 2. Where does the comparecustomname method get the parameters from. its very confusing how it knows which parameters to use for the comparison.
Title: Implement Sort and Custom Enumerator in Generic List   
Name: Eric Ramírez
Date: 2010-04-09 11:58:27 PM
Comment:
The best article that i´ve found.

Thanks.
Title: Implement Sort and Custom Enumerator in Generic List   
Name: Saurabh
Date: 2008-12-25 12:16:29 PM
Comment:
Very nice explanation in a concise way...exactly to the point.
Title: Implement Sort and Custom Enumerator in Generic List   
Name: Michael
Date: 2008-04-12 10:30:13 PM
Comment:
Comprehensive and compact guide. And examples are actually working, in contrast to some MSDN articles
Title: Implement Sort and Custom Enumerator in Generic List   
Name: Wayde
Date: 2008-01-03 8:46:00 PM
Comment:
I have read a lot of stuff about custom enumeration and sorters and haven't understood any of it until I got to this article. Great Job! The article is concise, well organized, and the examples are fantastic.

Thank you.
Title: Implement Sort and Custom Enumerator in Generic List   
Name: Cheri
Date: 2008-01-03 3:02:25 AM
Comment:
cool article, learnt a lot of stuff from it






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-23 10:39:52 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search