-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentsSpecialties.cs
58 lines (50 loc) · 2.42 KB
/
StudentsSpecialties.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Create a class StudentSpecialty that holds specialty name and faculty number. Create a list of student specialties, where each specialty corresponds to a certain student (via the faculty number). Print all student names alphabetically along with their faculty number and specialty name. Use the "join" LINQ operator.
*/
using System;
using System.Collections.Generic;
using System.Linq;
namespace _12StudentsSpecialties
{
class Program
{
class FacNumName
{
public int FacNum { get; set;}
public string name { get; set; }
}
class StudentSpecialtyClass
{
public string SpecialtyName { get; set; }
public int FacultyNumber { get; set; }
}
static void Main(string[] args)
{
List<StudentSpecialtyClass> allStudent = new List<StudentSpecialtyClass>
{
new StudentSpecialtyClass {SpecialtyName = "Web Developer", FacultyNumber= 203314},
new StudentSpecialtyClass {SpecialtyName = "Web Developer", FacultyNumber= 203114},
new StudentSpecialtyClass {SpecialtyName = "PHP Developer",FacultyNumber= 203814},
new StudentSpecialtyClass {SpecialtyName = "PHP Developer", FacultyNumber= 203914},
new StudentSpecialtyClass {SpecialtyName = "QA Engineer", FacultyNumber= 203314},
new StudentSpecialtyClass {SpecialtyName = "Web Developer", FacultyNumber= 203914},
};
List <FacNumName> nameForJoin = new List <FacNumName>
{
new FacNumName { FacNum = 215314, name= "Milena Kirova"},
new FacNumName { FacNum =203114, name= "Stefan Popov"},
new FacNumName { FacNum =203314, name= "Asya Manova"},
new FacNumName { FacNum =203914,name= "Diana Petrova"},
new FacNumName { FacNum =203814,name= "Ivan Ivanov"}
};
var result =
from n in nameForJoin
join a in allStudent on n.FacNum equals a.FacultyNumber
select new { n.name, n.FacNum, a.SpecialtyName };
var sorted = result.OrderBy(x => x.name);
foreach (var item in sorted)
{
Console.WriteLine(item.name+ " "+item.FacNum+" "+ item.SpecialtyName);
}
}
}
}