Started work to enable nullable on Chapter 04
ADD
src/Chapter04.Tests/Listing04.62.Tests.cs
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_62
+{
+ [TestClass]
+ public class EmailDomainTests
+ {
+ [TestMethod]
+ public void Main_EnterValidEmailWithDomain_WriteDomain()
+ {
+ const string expected = @"
+---+---+---
+ 1 | 2 | 3
+---+---+---
+ 4 | 5 | 6
+---+---+---
+ 7 | 8 | 9
+---+---+---";
+
+ IntelliTect.TestTools.Console.ConsoleAssert.Expect(
+ expected, Program.Main);
+ }
+ }
+}
\ No newline at end of file

MODIFY
src/Chapter04/Listing04.31.EqualityOperator.cs
src/Chapter04/Listing04.31.EqualityOperator.cs
@@ -10,7 +10,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_31
}
}
- public static string input { get; set; }
- public static string currentPlayer { get; set; }
+#pragma warning disable IDE1006 // Promoted local variables to properties to support testing sample code
+ public static string input { get; set; } = "Let the game beging!";
+ public static string? currentPlayer { get; set; }
+#pragma warning restore IDE1006 // Naming Styles
}
}

MODIFY
src/Chapter04/Listing04.37.NullConditionalOperator.cs
src/Chapter04/Listing04.37.NullConditionalOperator.cs
@@ -2,6 +2,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_36A
{
class Program
{
+#nullable disable
static void Main(string[] args)
{
if (args?.Length == 0)

MODIFY
src/Chapter04/Listing04.38.NullConditionalOperatorWithIndexOperator.cs
src/Chapter04/Listing04.38.NullConditionalOperatorWithIndexOperator.cs
@@ -4,6 +4,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_38
{
public static void Main(string[] args)
{
+#nullable disable
// CAUTION: args?.Length not verified
string directoryPath = args?[0];
string searchPattern = args?[1];

MODIFY
src/Chapter04/Listing04.44.DoWhileLoop.cs
src/Chapter04/Listing04.44.DoWhileLoop.cs
@@ -4,6 +4,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_44
{
public static void Main()
{
+ int currentPlayer = 1;
+
// Repeatedly request player to move until he
// enters a valid position on the board
bool valid;
@@ -21,7 +23,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_44
} while(!valid);
}
-
- public static object[] currentPlayer { get; set; }
}
}

MODIFY
src/Chapter04/Listing04.48.InputValidation.cs
src/Chapter04/Listing04.48.InputValidation.cs
@@ -38,6 +38,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_48
// ...
}
- public static string input { get; set; }
+ public static string input { get; set; } = "Let the game begin!";
}
}

MODIFY
src/Chapter04/Listing04.51.SettingABit.cs
src/Chapter04/Listing04.51.SettingABit.cs
@@ -4,6 +4,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_51
{
public static void Main()
{
+
+ int[] playerPositions = { 0, 0 };
+ int currentPlayer = 1;
string input = "";
int shifter; // The number of places to shift
@@ -26,8 +29,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_51
// index in a zero based array.
playerPositions[currentPlayer - 1] |= position;
}
-
- public static int[] playerPositions { get; set; }
- public static int currentPlayer { get; set; }
}
}

MODIFY
src/Chapter04/Listing04.62.Regions.cs
src/Chapter04/Listing04.62.Regions.cs
@@ -6,6 +6,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_62
{
// ...
+ int border;
+ string[] borders = {
+ "|", "|", "\n---+---+---\n", "|", "|",
+ "\n---+---+---\n", "|", "|", ""
+ };
+ System.Collections.Generic.IEnumerable<char> cells = new char []{
+ '1', '2', '3', '4', '5', '6', '7', '8', '9'
+ };
+
+
#region Display Tic-tac-toe Board
#if CSHARP2PLUS
@@ -37,9 +47,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_62
// ...
}
-
- public static int border { get; set; }
- public static int[] borders { get; set; }
- public static System.Collections.Generic.IEnumerable<char> cells { get; set; }
}
}

MODIFY
src/Chapter04/TicTacToe.cs
src/Chapter04/TicTacToe.cs
@@ -11,7 +11,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.TicTacToe
// play tic-tac-toe.
public class TicTacToeGame // Declares the TicTacToeGame class.
{
- public static void Main() // Declares the entry point to the program.
+ static public void Main() // Declares the entry point to the program.
{
// Stores locations each player has moved.
int[] playerPositions = { 0, 0 };
@@ -22,8 +22,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.TicTacToe
// Winning player
int winner = 0;
- string input = null;
-
+ string input = "Let the game begin!";
// Display the board and
// prompt the current player

Started work to enable nullable on Chapter 04