Perhaps you are faced with situations in which you declare a certain enumeration, and you want to evaluate a certain object in order to find out which categories of enumerations it satisfies, i.e. an object can satisfy the conditions for its classification by more than one enumerator.
An example is, say, at a university, I have different courses, and this one has a list of students attending various specializations. Thus, we have
public class Course
{
int Id;
IList<Electrical> ElectricalStudents;
IList<Computer> ComputerStudents;
IList<Bioengineering> BioengineeringStudents;
IList<Mechanical> MechanicalStudents;
}
and my listing is as follows
public enum ParentDepartment
{
Electrical,
Mechanical,
Biology
}
and for each course object that I have, I need to determine which parent sections the students belong to, so that I can use them accordingly (so that I can send these departments)
? .
, , , :
public static IList<ParentDepartment> GetParentDepartments(Course course)
{
public parentDepartmentList=new List<ParentDepartment>();
if(ElectricalStudents.Count>0)
Add(parentDepartmentList,ParentDepartment.Electrical);
if(ComputerStudents.Count>0)
Add(parentDepartmentList,ParentDepartment.Electrical);
if(MechanicalStudents.Count>0)
Add(parentDepartmentList,ParentDepartment.Mechanical);
if(BioengineeringStudents.Count>0)
Add(parentDepartmentList,ParentDepartment.Biology);
}
private void Add(IList<ParentDepartment> parentDepartmentList,ParentDepartment parentdept)
{
if(!parentDepartmentList.Contains(parentdept))
parentDepartmentList.Add(parentdept);
}
, . , , , , .
. , . ?
.
P.S: , #, , .