Implicit Index Access

  • Operators can also be used in object initializers in C#13
				
					var empArray = new Employee[3];
empArray[^1] = new Employee() { Id="1", Salary=1000 };
empArray[^3] = new Employee() { Id="2", Salary=3000 };
empArray[^2] = new Employee() { Id="3", Salary=7000 };

foreach (var employee in empArray)
{
    Console.WriteLine("id:->" + employee.Id+ " and Salary is:" + employee.Salary);
}

				
			

Leave a Comment