mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-07 19:02:37 -08:00
Enabled nullable reference types
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -8,16 +8,22 @@
|
||||
/// <summary>
|
||||
/// Gets the company's name.
|
||||
/// </summary>
|
||||
public string Name { get; init; }
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the company's three letter stock symbol.
|
||||
/// </summary>
|
||||
public string StockSymbol { get; init; }
|
||||
public string StockSymbol { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the company's current share price.
|
||||
/// </summary>
|
||||
public double SharePrice { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new Company record.
|
||||
/// </summary>
|
||||
public Company(string name, string stockSymbol, double sharePrice) =>
|
||||
(Name, StockSymbol, SharePrice) = (name, stockSymbol, sharePrice);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,10 +97,15 @@ namespace Game
|
||||
while (true)
|
||||
{
|
||||
View.PromptBuySellCompany(company);
|
||||
if (Int32.TryParse(Console.ReadLine(), out var amount))
|
||||
return amount;
|
||||
|
||||
var input = Console.ReadLine();
|
||||
if (input is null)
|
||||
Environment.Exit(0);
|
||||
else
|
||||
if (!Int32.TryParse(input, out var amount))
|
||||
View.PromptValidInteger();
|
||||
else
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ namespace Game
|
||||
/// </summary>
|
||||
private static ImmutableArray<Company> Companies = ImmutableArray.CreateRange(new[]
|
||||
{
|
||||
new Company { Name = "INT. BALLISTIC MISSILES", StockSymbol = "IBM", SharePrice = 100 },
|
||||
new Company { Name = "RED CROSS OF AMERICA", StockSymbol = "RCA", SharePrice = 85 },
|
||||
new Company { Name = "LICHTENSTEIN, BUMRAP & JOKE", StockSymbol = "LBJ", SharePrice = 150 },
|
||||
new Company { Name = "AMERICAN BANKRUPT CO.", StockSymbol = "ABC", SharePrice = 140 },
|
||||
new Company { Name = "CENSURED BOOKS STORE", StockSymbol = "CBS", SharePrice = 110 }
|
||||
new Company("INT. BALLISTIC MISSILES", "IBM", sharePrice:100),
|
||||
new Company("RED CROSS OF AMERICA", "RCA", sharePrice:85 ),
|
||||
new Company("LICHTENSTEIN, BUMRAP & JOKE", "LBJ", sharePrice:150),
|
||||
new Company("AMERICAN BANKRUPT CO.", "ABC", sharePrice:140),
|
||||
new Company("CENSURED BOOKS STORE", "CBS", sharePrice:110)
|
||||
});
|
||||
|
||||
static void Main()
|
||||
|
||||
Reference in New Issue
Block a user