-
Notifications
You must be signed in to change notification settings - Fork 0
/
Records.cs
57 lines (47 loc) · 1.42 KB
/
Records.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
using System;
using System.Collections.Generic;
namespace DriverUsageAnalysis
{
public record MovieRecord(string Title, int Released, string Tagline, List<ActorRecord> Cast)
{
public void WriteToConsole()
{
Console.WriteLine("Movie record:\n\t" + Title + "\n\t" + Released + "\n\t" + Tagline);
}
}
public record ActorRecord(string Name)
{
public void WriteToConsole()
{
Console.WriteLine("Actor record:\n\t" + Name);
}
}
/* NOTE: The above immutable record type was introduced with C# 9.0. The below classes show what they basically implement.
public class MovieRecord
{
public string Title { get; }
public int Released { get; }
public string Tagline { get; }
public List<Actor> Cast { get; } = new(); //C# 9.0 version of new List<Actor>()
public MovieRecord(string title, int released, string tagline, List<Actor> cast)
{
Title = title;
Released = released;
Tagline = tagline;
Cast = cast;
}
public override string ToString()
{
return "Movie record:\n\t" + Title + "\n\t" + Released + "\n\t" + Tagline;
}
}
public class ActorRecord
{
public string Name { get; }
public ActorRecord(string name)
{
Name = name;
}
}
*/
}