【发布时间】:2015-10-06 01:25:52
【问题描述】:
我正在制作一个程序,将不同的参与者放入具有特定密钥的库中。我遇到了KeyNotFoundException 的问题。
在这里你可以看到我在if (sessionPersonsSchedule[s].Count == s.MaxParticipants)的代码错误
public bool personAddToLibrary(int personsIn)
{
if (personsIn == participants.Count)
{
return true;
}
else
{
for ( int j = 0; j < participants[personsIn].Preferences.Count; j++ )
{
Participant p = participants[personsIn];
Session s = sessions[p.Preferences[j] - 1];
SessionPersonsSchedule[s]
if (testSessions(s))
{
sessionPersonsSchedule[s].Add(p);
Console.Write(personsIn + ". " + p + "is added to session " + s);
personAddToLibrary(personsIn + 1);
if (personsIn == participants.Count)
{
return true;
}
}
else
{
sessionPersonsSchedule[s].Remove(p);
Console.Write(personsIn + ". " + p + "is deleted from session " + s);
}
}
}
return false;
}
public bool testSessions(Session s)
{
if (sessionPersonsSchedule[s].Count == s.MaxParticipants)
{
return false;
}
else
{
return true;
}
}
【问题讨论】:
标签: c#