-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathProgram.cs
More file actions
39 lines (29 loc) · 896 Bytes
/
Program.cs
File metadata and controls
39 lines (29 loc) · 896 Bytes
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
using Pizzeria;
using System.Text.Json;
var person = new Person
{
FirstName = "John",
LastName = "Smith",
YearOfBirth = 1972
};
var asJson = JsonSerializer.Serialize(person);
Console.WriteLine("As JSON:");
Console.WriteLine(asJson);
var personJson =
"{\"FirstName\":\"John\",\"LastName\":\"Smith\",\"YearOfBirth\":1972}";
var personFromJson = JsonSerializer.Deserialize<Person>(personJson);
var numbers = new List<int> { 1, 4, 6, -1, 12, 44, -8, -19 };
bool shallAddPositiveOnly = false;
NumbersSumCalculator calculator =
shallAddPositiveOnly ?
new PositiveNumbersSumCalculator() :
new NumbersSumCalculator();
int sum = calculator.Calculate(numbers);
Console.WriteLine("Sum is: " + sum);
Console.ReadKey();
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int YearOfBirth { get; set; }
}