.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Find max and min value from an ArrayList

Posted By:Amit Mehra       Posted Date: November 26, 2008    Points: 10    Category: Collections    URL: http://www.dotnetspark.com  
 

Below are the two static method to find Max and Min Value from an ArrayList. This method take ArrayList as an Input and give the Maximum/Minimum value from an ArrayList.The code is written in C#.

Lets see the function. Before using this function you have to add System.Collections Namespace to top of your .cs file like this.

using System.Collections;

1)Method to find the minimum value from an ArrayList

public static object GetMinValue(ArrayList arrList)

{

ArrayList sortArrayList = arrList;

sortArrayList.Sort();

return sortArrayList[0];

}

2) Method to find Maximum value from an ArrayList

public static object GetMaxValue(ArrayList arrList)

{

ArrayList sortArrayList = arrList;

sortArrayList.Sort();

sortArrayList.Reverse();

return sortArrayList[0];

}

 


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend