C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Anonymous Methods in C#


Posted Date: 08 May 2007    Resource Type: Code Snippets    Category: Collections

Posted By: santosh narayan poojari       Member Level: Silver
Rating:     Points: 10



Anonymous Method of C#2.0 can ease Sorting operation in Ascending / Descending order on Generic collection List. One can avoid tedious use of implementing IComparable / IComparer for List. This sample code shows how to use Anonymous methdos in C#.


protected void Page_Load(object sender, EventArgs e)
{
List customerList = new List();
customerList.Add(new Customer(01111, "Santosh"));
customerList.Add(new Customer(01112, "Narayan"));
customerList.Add(new Customer(01113, "Poojari"));
customerList.Sort(
delegate(Customer lhs, Customer rhs) {
return lhs.CustomerID.CompareTo(rhs.CustomerID);
//OR return rhs.CustomerID.CompareTo(lhs.CustomerID);
});
//one can use customerList.Reverse() to reverse the sort order
foreach (Customer customer in customerList)
Response.Write(customer.CustomerID+"
");
}
public class Customer
{
private int m_CustomerID = int.MinValue;
private string m_CustomerName = string.Empty;
public Customer(int customerId,string customerName)
{
this.m_CustomerID = customerId;
this.m_CustomerName = customerName;
}
public int CustomerID
{
get { return m_CustomerID; }
set { m_CustomerID = value; }
}
public string CustomerName
{
get { return m_CustomerName; }
set { m_CustomerName = value; }
}
}




Responses

Author: Vasudevan Deepak Kumar    18 Jul 2007Member Level: Diamond   Points : 0
I would say this tool would better befit in this URL (http://www.dotnetspider.com/tutorials/BestPractices.aspx)


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Iterator,Delegate,Predicates,Anonymous method and Generics C#2.0
Previous Resource: Export Data from Listview to Excel
Return to Discussion Resource Index
Post New Resource
Category: Collections


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference call definitions

Contact Us    Privacy Policy    Terms Of Use