Enabled nullable reference types

This commit is contained in:
Peter
2021-07-12 22:20:51 -04:00
parent eea78f037c
commit 1794bb048d
4 changed files with 21 additions and 11 deletions

View File

@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -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);
}
}

View File

@@ -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;
}
}
}

View File

@@ -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()