Destructor sample improvements.
RENAME
src/Chapter06.Tests/Listing06.38.StaticCopyMethodForDirectoryInfo.Tests.cs
src/Chapter06.Tests/Listing06.38.DefiningAndUsingADeconstructors.Tests.cs
@@ -8,9 +8,10 @@ public class ProgramTests
[TestMethod]
public void MainTest()
{
- const string expected = @"Inigo Montoya: Too Little
+ const string expected = """
Inigo Montoya: Too Little
-Inigo Montoya: Too Little";
+ Inigo Montoya: Too Little
+ """;
IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () =>
{
Program.Main();

ADD
src/Chapter06.Tests/Listing06.38A.ImplicitlyInvokingDeconstructors.Tests.cs
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_38A.Tests;
+
+[TestClass]
+public class ProgramTests
+{
+ [TestMethod]
+ public void MainTest()
+ {
+ const string expected = """
+ Inigo Montoya: Too Little
+ Inigo Montoya: Too Little
+ """;
+ IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () =>
+ {
+ Program.Main();
+ });
+ }
+}

MODIFY
src/Chapter06/Listing06.38.DefiningAndUsingADeconstructors.cs
src/Chapter06/Listing06.38.DefiningAndUsingADeconstructors.cs
@@ -114,14 +114,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_38
System.Console.WriteLine(
"{0} {1}: {2}",
firstName, lastName, salary);
-
- #region EXCLUDE
- (_, firstName, lastName, salary) = employee;
-
- System.Console.WriteLine(
- "{0} {1}: {2}",
- firstName, lastName, salary);
- #endregion EXCLUDE
}
}
#endregion INCLUDE

ADD
src/Chapter06/Listing06.38A.ImplicitlyInvokingDeconstructors.cs
+using AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_38;
+
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_38A
+{
+ #region INCLUDE
+ public class Program
+ {
+ public static void Main()
+ {
+ Employee employee;
+ employee = new ("Inigo", "Montoya")
+ {
+ // Leveraging object initializer syntax
+ Salary = "Too Little"
+ };
+
+ #region EXCLUDE
+ System.Console.WriteLine(
+ "{0} {1}: {2}",
+ employee.FirstName,
+ employee.LastName,
+ employee.Salary);
+ #endregion EXCLUDE
+
+ #region HIGHLIGHT
+ (_, string firstName, string lastName, string? salary) = employee;
+ #endregion HIGHLIGHT
+
+ System.Console.WriteLine(
+ "{0} {1}: {2}",
+ firstName, lastName, salary);
+ }
+ }
+ #endregion INCLUDE
+}

Destructor sample improvements.