-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStarshipsExample.cs
More file actions
36 lines (32 loc) · 1.08 KB
/
Copy pathStarshipsExample.cs
File metadata and controls
36 lines (32 loc) · 1.08 KB
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
namespace Example
{
using System;
using StarWarsApiCSharp;
public class StarshipsExample : IExecutor
{
public void Execute()
{
int starshipId = 3;
int nonExistingId = 1;
IRepository<Starship> starshipRepo = new Repository<Starship>();
Starship starshipDetails = starshipRepo.GetById(starshipId);
Starship anotherStarship = starshipRepo.GetById(nonExistingId);
this.PrintStarshipName(starshipDetails, starshipId);
this.PrintStarshipName(anotherStarship, nonExistingId);
}
//// if anotherStarship is null this will throw an exception.
//// Console.WriteLine(another.Name);
//// So make sure starship is found!
private void PrintStarshipName(Starship starship, int starshipID)
{
if (starship != null)
{
Console.WriteLine(starship.Name);
}
else
{
Console.WriteLine("Cannot find starship with id: " + starshipID);
}
}
}
}