I have a list of objects, each with various properties, built from a constructor, as below:
I am trying to form a list of lists, so that where the 'LevelNumber' matches it will create a list which will be added to a list according to unique 'LevelNumber' ordered by number. I think what's below must be somewhere close to what I need:
List<Job> JobList = new List<Job>();
JobList.Add(new Job("Owner", null, 0, "ProjectBriefCreation", 1, "ProjectOwner", 5, 2, 2));
JobList.Add(new Job("Carpentry", "GeneralContractor", 2, "Drywalling", 1, "Carpenter", 5, 2, 2));
JobList.Add(new Job("PlasteringAndPainting", "GeneralContractor", 2, "Plastering", 2, "Plasterer", 6, 2, 2));
JobList.Add(new Job("PlasteringAndPainting", "GeneralContractor", 2, "Painting", 3, "Painter", 8, 2, 2));
JobList.Add(new Job("GeneralContractor", "Owner", 1, "ProjectManagement", 1, "ContractsManager", 7, 2, 2));
JobList.Add(new Job("DesignContractor", "Owner", 1, "DesignManagement", 1, "DesignContractsManager", 7, 2, 2));
JobList.Add(new Job("ArchitecturalPractice", "DesignContractor", 1, "BuildingDesign", 1, "LeadArchitect", 7, 2, 2));
JobList.Add(new Job("StructuralEngineeringPractice", "DesignContractor", 1, "StructuralDesign", 1, "StructuralEngineer", 7, 2, 2));
List<List<Job>> jobsPerLevelList = new List<List<Job>>();
List<int> distinctLevelNumber = new List<int>();
distinctLevelNumber.AddRange(JobList.Select(x => x.LevelNumber).Distinct().ToList());
foreach (var Level in distinctLevelNumber)
{
if (Job.LevelNumber.)
{
jobsPerLevelList.Add(new List<Job>(Job.LevelNumber));
}
}
I can't quite seem to get it finished/working. Any advice would be appreciated.
I am trying to form a list of lists, so that where the 'LevelNumber' matches it will create a list which will be added to a list according to unique 'LevelNumber' ordered by number. I think what's below must be somewhere close to what I need:
List<Job> JobList = new List<Job>();
JobList.Add(new Job("Owner", null, 0, "ProjectBriefCreation", 1, "ProjectOwner", 5, 2, 2));
JobList.Add(new Job("Carpentry", "GeneralContractor", 2, "Drywalling", 1, "Carpenter", 5, 2, 2));
JobList.Add(new Job("PlasteringAndPainting", "GeneralContractor", 2, "Plastering", 2, "Plasterer", 6, 2, 2));
JobList.Add(new Job("PlasteringAndPainting", "GeneralContractor", 2, "Painting", 3, "Painter", 8, 2, 2));
JobList.Add(new Job("GeneralContractor", "Owner", 1, "ProjectManagement", 1, "ContractsManager", 7, 2, 2));
JobList.Add(new Job("DesignContractor", "Owner", 1, "DesignManagement", 1, "DesignContractsManager", 7, 2, 2));
JobList.Add(new Job("ArchitecturalPractice", "DesignContractor", 1, "BuildingDesign", 1, "LeadArchitect", 7, 2, 2));
JobList.Add(new Job("StructuralEngineeringPractice", "DesignContractor", 1, "StructuralDesign", 1, "StructuralEngineer", 7, 2, 2));
List<List<Job>> jobsPerLevelList = new List<List<Job>>();
List<int> distinctLevelNumber = new List<int>();
distinctLevelNumber.AddRange(JobList.Select(x => x.LevelNumber).Distinct().ToList());
foreach (var Level in distinctLevelNumber)
{
if (Job.LevelNumber.)
{
jobsPerLevelList.Add(new List<Job>(Job.LevelNumber));
}
}
I can't quite seem to get it finished/working. Any advice would be appreciated.
Last edited: