0% found this document useful (0 votes)
16 views2 pages

Internal Class Employee

The document defines an 'Employee' class with properties for employee ID, name, and salary. It also includes an 'EmployeeUtility' class that manages an array of Employee objects, allowing for retrieval and modification of employee names using an indexer. The 'Program' class demonstrates the functionality by creating an instance of 'EmployeeUtility', displaying employee details, and modifying an employee's name.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Internal Class Employee

The document defines an 'Employee' class with properties for employee ID, name, and salary. It also includes an 'EmployeeUtility' class that manages an array of Employee objects, allowing for retrieval and modification of employee names using an indexer. The 'Program' class demonstrates the functionality by creating an instance of 'EmployeeUtility', displaying employee details, and modifying an employee's name.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

internal class Employee

{
public int EmpID { get; set; }
public string Name { get; set; }
public double Salary { get; set; }
}
using System; using System.Collections.Ge... by T V S Koushik
T V S Koushik
10:32 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Indexers
{
internal class EmployeeUtility
{
Employee[] employees = null;
public EmployeeUtility()
{
employees = new Employee[4];
employees[0] = new Employee() { EmpID = 101, Name = "Scott", Salary =
12356 };
employees[1] = new Employee() { EmpID = 102, Name = "Ram", Salary =
45645 };
employees[2] = new Employee() { EmpID = 103, Name = "Roger", Salary =
75675 };
employees[3] = new Employee() { EmpID = 104, Name = "Shyam", Salary =
23564 };
}

public string this[int id]


{
get
{
string name = string.Empty;
foreach (Employee e in employees)
{
if (e.EmpID == id)
{
name = e.Name;
break;
}
}
return name;
}
set
{
foreach (Employee e in employees)
{
if (e.EmpID == id)
{
e.Name = value;
break;
}
}
}
}
public void ViewEmployees()
{
Console.WriteLine("EmpID\tName\tSalary");
Console.WriteLine("-----------------------");
foreach (Employee e in employees)
{
Console.WriteLine($"{e.EmpID}\t{e.Name}\t{e.Salary}");
}
}
}
}

using System; namespace Indexers { ... by T V S Koushik


T V S Koushik
10:33 AM
using System;

namespace Indexers
{
internal class Program
{
static void Main(string[] args)
{
EmployeeUtility utility = new EmployeeUtility();
utility.ViewEmployees();
string name = utility[102];
Console.WriteLine("Name is {0}", name);
utility[103] = "Koushik";
utility.ViewEmployees();
}
}
}

has context menu

You might also like