diff --git a/83 Stock Market/csharp/Game.csproj b/83 Stock Market/csharp/Game.csproj index 20827042..849a99d4 100644 --- a/83 Stock Market/csharp/Game.csproj +++ b/83 Stock Market/csharp/Game.csproj @@ -1,8 +1,7 @@ - Exe net5.0 + enable - diff --git a/83 Stock Market/csharp/src/Company.cs b/83 Stock Market/csharp/src/Company.cs index 59f40e8d..86c4e4ba 100644 --- a/83 Stock Market/csharp/src/Company.cs +++ b/83 Stock Market/csharp/src/Company.cs @@ -8,16 +8,22 @@ /// /// Gets the company's name. /// - public string Name { get; init; } + public string Name { get; } /// /// Gets the company's three letter stock symbol. /// - public string StockSymbol { get; init; } + public string StockSymbol { get; } /// /// Gets the company's current share price. /// public double SharePrice { get; init; } + + /// + /// Initializes a new Company record. + /// + public Company(string name, string stockSymbol, double sharePrice) => + (Name, StockSymbol, SharePrice) = (name, stockSymbol, sharePrice); } } diff --git a/83 Stock Market/csharp/src/Controller.cs b/83 Stock Market/csharp/src/Controller.cs index bccfde0c..87a1dc7d 100644 --- a/83 Stock Market/csharp/src/Controller.cs +++ b/83 Stock Market/csharp/src/Controller.cs @@ -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; } } } diff --git a/83 Stock Market/csharp/src/Program.cs b/83 Stock Market/csharp/src/Program.cs index 552d8c9a..8d2b2a98 100644 --- a/83 Stock Market/csharp/src/Program.cs +++ b/83 Stock Market/csharp/src/Program.cs @@ -11,11 +11,11 @@ namespace Game /// private static ImmutableArray 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()