Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Author: Yash D. Saraf <https://github.com/yashdsaraf>
- using System;
- using System.Collections;
- class Sample {
- static void Main() {
- ArrayList list = new ArrayList();
- // Add elements to list using ArrayList.Add( string element ) method
- list.Add( "Mercury" );
- list.Add( "Venus" );
- list.Add( "Earth" );
- list.Add( "Mars" );
- list.Add( "Jupiter" );
- list.Add( "Saturn" );
- list.Add( "Uranus" );
- list.Add( "Neptune" );
- // Get capacity of list using ArrayList.Capacity property
- Console.WriteLine( "Size: {0}", list.Capacity );
- // Get number of elements in list using ArrayList.Count property
- Console.WriteLine( "No. of elements: {0}", list.Count );
- Console.WriteLine( "Elements: " );
- PrintVals( list );
- Console.WriteLine( "Elements sorted in ascending order: " );
- // Sort elements in list using ArrayList.Sort() method
- list.Sort();
- PrintVals( list );
- Console.WriteLine( "Elements sorted in descending order: " );
- // Reverse elements in list using ArrayList.Reverse() method
- list.Reverse();
- PrintVals( list );
- Console.ReadKey();
- }
- private static void PrintVals( ArrayList list ) {
- foreach ( string s in list )
- Console.WriteLine( "\t{0}", s );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment