-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
91 lines (73 loc) · 2.46 KB
/
Program.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System.Collections.Generic;
namespace TargetTypedNewExpressions
{
/// <summary>
/// https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/target-typed-new
/// https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9
/// </summary>
class Program
{
static void Main(string[] args)
{
Student student01 = new(1, "İbrahim", "ATAY");
Student student02 = new()
{
Id = 1,
FirstName = "İbrahim",
LastName = "ATAY"
};
// Course course01 = new("Computer Architecture"); //compilation error
Course course02 = new(1, "Digital Circuits");
course02.AddToStudent(new ());
student02.AddToCourse(new ());
student02.AddToCourse(new(1, "Computer Organization"));
School school = new("Sakarya University"); // record
Dictionary<string, int[]> cacheDictionary = new()
{
{"Index01", new[] {1, 2, 4, 5}},
{"Index02", new[] {9, 8, 7, 6}},
{"Index03", new[] {2, 3, 1, 0}}
};
List<Student> students = new()
{
new(1,"İbrahim", "ATAY")
};
(int x, int y) eastCoordinate = new(26, 45);
(int x, int y) northCoordinate = new(36, 42);
// dynamic variable01 = new(); //compilation error
}
}
class Student
{
public Student()
{
_courses = new();
}
public Student(int id, string firstName, string lastName)
{
Id = id;
FirstName = firstName;
LastName = lastName;
_courses = new();
}
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
private readonly List<Course> _courses;
public void AddToCourse(Course course) => _courses.Add(course);
}
class Course
{
public Course(int id = 1, string name = "Computer Engineering")
{
Id = id;
Name = name;
_students = new();
}
public int Id { get; set; }
public string Name { get; set; }
private readonly List<Student> _students;
public void AddToStudent(Student student) => _students.Add(student);
}
record School(string Name);
}