generated from nashville-software-school/vs-code-debug-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
59 lines (50 loc) · 1.68 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
using System;
using System.Collections.Generic;
using System.Linq;
namespace DebuggingDemo
{
class Program
{
private static List<Author> _authors = new List<Author>
{
new Author { Id = 1, Name = "Stephen King" },
new Author { Id = 2, Name = "Sylvia Plath" },
new Author { Id = 3, Name = "Martin Fowler" }
};
private static List<Book> _books = new List<Book>
{
new Book { Id = 1, Title = "The Shining", AuthorId = 1 },
new Book { Id = 2, Title = "The Gunslinger", AuthorId = 1 },
new Book { Id = 3, Title = "The Bell Jar", AuthorId = 2 },
new Book { Id = 4, Title = "Refactoring", AuthorId = 3 },
new Book { Id = 5, Title = "Lady Lazarus", AuthorId = 2 },
};
static void Main(string[] args)
{
var author = GetAuthorByName("Stephen King");
if (author == null)
{
Console.WriteLine("Author was not found");
}
var books = GetBooksByAuthor(author.Id);
if (books == null)
{
Console.WriteLine("No books by that author");
}
foreach (var book in books)
{
Console.WriteLine(book.Title);
}
}
private static Author GetAuthorByName(string name)
{
var author = _authors.FirstOrDefault(a => a.Name == name);
return author;
}
private static List<Book> GetBooksByAuthor(int authorId)
{
var books = _books.Where(b => b.AuthorId == authorId).ToList();
return books;
}
}
}