This comprehensive example demonstrates the evolution of data storage in C#, from basic arrays to modern generic collections. It shows various data structures, their problems, and solutions, along with performance considerations and best practices.
Emp emp1 = new Emp();
emp1.No = 1;
emp1.Name = "Jayesh";
emp1.Address = "Karad";
emp1.EMail = "[email protected]";
// Similar for emp2 and emp3...
Creates three sample Employee objects to demonstrate various collection operations throughout the examples.
// Method 1: Declaration then assignment
int[] arr = new int[3];
arr[0] = 99;
arr[1] = 22;
arr[2] = 55;
// arr[3] = 30; // IndexOutOfRangeException!
// Method 2: Initialization
int[] arr = new int[] { 10, 20, 30, 40, 50 };
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine(arr[i]);
}
arr[3]
when size is 3 throws exception