Program
Output
29
49
52
57
69
76
76
78
84
85
Trainee Names.......
Meenakshi
Anishurahman
Saksham
Prithvi
After sorting Trainee Names......
Anishurahman
Meenakshi
Prithvi
Saksham
using System;
using System.Collections.Generic; //<-this namespace is required
namespace Collections
{
class GenericCollectionsList
{
static void Main(string[] args)
{
// Creating a
List of integers
List<int>
mylist = new List<int>();
Random rnd = new Random();
for (int x = 1; x
<= 10; x++)
{
mylist.Add(rnd.Next(10, 99));
}
mylist.Sort();
//Displaying
items of my list by using foreach loop
foreach (int item in mylist)
{
Console.WriteLine(item);
}
//Creating a
List of Strings..
List<string>
Trainees = new List<string>();
Trainees.Add("Meenakshi");
Trainees.Add("Anishurahman");
Trainees.Add("Saksham");
Trainees.Add("Prithvi");
Console.WriteLine("\nTrainee Names.......");
foreach (string item in Trainees)
{
Console.WriteLine(item);
}
Trainees.Sort();
Console.WriteLine("\nAfter sorting Trainee
Names......");
foreach (string item in Trainees)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
}
}
29
49
52
57
69
76
76
78
84
85
Trainee Names.......
Meenakshi
Anishurahman
Saksham
Prithvi
After sorting Trainee Names......
Anishurahman
Meenakshi
Prithvi
Saksham
No comments:
Post a Comment