我正在嘗試在下面的字典鍵中獲取最低和最高值
public static Dictionary<SimulationResult, List<Student>> SimulationOutput { get; set; } = new Dictionary<SimulationResult, List<Student>>();
這是鍵中的類
internal class SimulationResult
{
public int Unsolved { get; set; }
public int ValuePreferences { get; set; }
public int Index { get; set; }
}
我收到序列中的錯誤在下面的行中不包含任何元素
int bestResult = SimulationOutput.Keys.Where(x=> x != null).Select(x => x.ValuePreferences).Max();
也在這些線上
int bestResult = SimulationOutput.Keys.Select(x => x.ValuePreferences).Max();
int LowestUnsonved = SimulationOutput.Keys.Select(x => x.Unsolved).Min();
字典填充在并行 for 回圈中。
Parallel.For(1, verwerken.Gegevens.AantalIteraties 1, i =>
{
PracticumCollectie practicumCollectie = verwerken.Data.PracticumCollectie.Copy();
StudentCollectie studentCollectie = verwerken.Data.StudentCollectie.Copy();
studentCollectie.OrderStudentByPreference();
studentCollectie.AssiningStudentToPracticum(practicumCollectie);
practicumCollectie.Oplossing.Index = i;
practicumCollectie.ZetAantalOnopgeloste(studentCollectie);
practicumCollectie.ZetWaardeVoorkeuren(studentCollectie);
bool schrijfOplossing = verwerken.Keuze.IsSimuleren ? verwerken.VoldoetAanOndergrenzen(practicumCollectie.Oplossing) : true;
if (schrijfOplossing)
{
SimulationOutput.Add(verwerken.GetBestandsnaam(practicumCollectie.Oplossing), new List<Student>(studentCollectie.Items));
}
});
uj5u.com熱心網友回復:
如果您使用 Parallel,則必須使用 ConcurrentDictionary。
普通字典不是執行緒安全的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/438274.html
下一篇:兩個集合類之間的流利斷言
