C Sharp - Populate Object during Declaration

Sample Initialization

Here is an example of declaring a list object and populate it with a few note objects. Those objects have an embedded object.

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
return new List<NoteDto>
{
new NoteDto
{
CompanyKey = "0",
ApplicationKey = "Vendor",
ApplicationSubKey = "1",
Dt = DateTime.Parse("2014-02-07"),
Note = "First Note",
NoteTypeEntity = new NoteTypeDto
{
CompanyKey = "0",
ApplicationKey = "Vendor",
Id = 4,
NoteType = "NewsFlash",
ShowOnNew = true
},
Who = "maw",
Id = 1
},
new NoteDto
{
CompanyKey = "0",
ApplicationKey = "Vendor",
ApplicationSubKey = "1",
Dt = new DateTime(2023, 01, 12),
Note = "Jan 15 - they came into the office for the first visit.",
NoteTypeEntity = new NoteTypeDto
{
ApplicationKey = "Vendor",
CompanyKey = "0",
NoteType = "Timeline",
ShowOnNew = false,
Id = 3
},
Who = "maw",
Id = 2
}
};