【发布时间】:2018-05-20 13:19:41
【问题描述】:
我有 3 个课程:
public class Disciplina
{
public int Key { get; set; }
public string Name { get; set; }
public string[] Semestr { get; set; }
public int Time { get; set; }
public List<int> TimeToAll { get; set; }
public string Otchetnost { get; set; }
public int Specialnost { get; set; }
...
}
public class Cafedra
{
public int Key { get; set; }
public string Name { get; set; }
public string Facultet { get; set; }
public string Telefone { get; set; }
public List<int> Specializations { get; set; }
...
}
public class Specialization
{
public int Key { get; set; }
public string Name { get; set; }
public string SpecialName { get; set; }
public string FormaObuch { get; set; }
public string[] DisplinsID { get; set; }
...
}
我需要选择所选咖啡厅的所有学科。我由许多 foreach 创建,但我需要 linq。
我试过了,但是一个Cafedra可以有很多Specialization,而Specialization可以有很多Disiplins,我不知道在LINQ中如何选择?
我的方法
private static void DiscipliniCafedri()
{
Console.WriteLine("Выберите кафедру:");
for (int i = 0; i < Cafedras.Count; i++)
{
Console.WriteLine(i + 1 + " " + Cafedras[i].ToString());
}
int ID = Convert.ToInt32(Console.ReadLine());
List<Specialization> spesc = new List<Specialization>();
Console.Clear();
Console.WriteLine("Дисциплины выбранной кафедры:");
foreach (int s in Cafedras[ID - 1].Specializations)
{
spesc.Add(Specializations[s - 1]);
}
foreach (Specialization s in spesc)
{
foreach (string d in s.DisplinsID)
{
Console.WriteLine(Disciplinas[Convert.ToInt32(d) - 1].Name);
}
}
}
【问题讨论】:
-
Selectmany 例如cagedra.selectmany(c=>c.specilation )
-
在英语中,“кафедра”是“department”,“дисциплина”在大学建模的语境中通常翻译为“subject”。