Write a department class Deptment:
Field: a collection of one for store employees List
Properties: the department name (the DeptName), the department number (DeptID)
the indexer 1: provide an incoming employee name and employee number parameters only write the indexer, add employees of the departments to realize the function
2: indexer introduced into employee names provide a read-only property, implement fuzzy query through the employee name to match all the employee object,
The class Deptment
{
Public int DeptNo;
Public string the DeptName.
Private List
Public Deptment (int count)
{
Emp=new List
}
///indexer 1: provide an incoming employee name and employee number parameters only write the indexer, add employees of the departments to realize the function
Public Employee this [string name, int ID]
{
Set
{
Foreach (Employee e in emp)
{
if (name !="" & amp; & The name!=e.n ame & amp; & ID! E.I=D)
{
E.D eptName=value. The DeptName;
}
}
}
}
///indexer 2: provide an incoming employee name read-only property, implement fuzzy query through the employee name to match all the employee object,
Public Employee this [string name]
{
The get
{
While (true)
{
Foreach (Employee emp1 in
{
If (name==emp1. ToString ())
{
Return emp1;
}
The else
for (int i=0; i
If (name==emp1. ToString (). The Substring (I, 1))
{
Return emp1;
}
}
}
The Employee emp=new Employee ();
An emp. Name="no such person";
return null;
}
}
}
}
}
The operations would not!
CodePudding user response:
Why is the index, not the method?CodePudding user response:
2 can be caused by this [string memberName]; This [int memberNo] types may not be the same, like method overloading, the need to diversify parameter,