Addressed warnings in chapters 1-5
MODIFY
src/Chapter01/Listing01.11.DeclaringTwoVariablesWithinOneStatement.cs
src/Chapter01/Listing01.11.DeclaringTwoVariablesWithinOneStatement.cs
@@ -5,6 +5,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_11
public static void Main()
{
string message1, message2;
+
+ message1 = "My name is Inigo Montoya.";;
+ message2 = "You killed my father....";
+
+ System.Console.WriteLine(message1);
+ System.Console.WriteLine(message2);
}
}
}

MODIFY
src/Chapter01/Listing01.13.AssignmentReturningAValueThatCanBeassignedAgain.cs
src/Chapter01/Listing01.13.AssignmentReturningAValueThatCanBeassignedAgain.cs
@@ -7,7 +7,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_13
// ...
string requirements, miracleMax;
requirements = miracleMax = "It would take a miracle.";
- // ...
+
+ System.Console.WriteLine(miracleMax);
+
}
}
}

MODIFY
src/Chapter02/Listing02.19.AssigningNullToAString.cs
src/Chapter02/Listing02.19.AssigningNullToAString.cs
@@ -11,6 +11,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_19
faxNumber = null;
//...
+
+ System.Console.WriteLine(faxNumber);
}
}
}

MODIFY
src/Chapter03/Listing03.05.DeclaringAnArray.cs
src/Chapter03/Listing03.05.DeclaringAnArray.cs
+#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_05
{
public class Program

MODIFY
src/Chapter03/Listing03.06.DeclaringATwoDimensionalArray.cs
src/Chapter03/Listing03.06.DeclaringATwoDimensionalArray.cs
+#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_06
{
public class Program

MODIFY
src/Chapter04/Listing04.19.DeclaringConstants.cs
src/Chapter04/Listing04.19.DeclaringConstants.cs
+#pragma warning disable CS0168 // Variable is declared but never used
+#pragma warning disable CS0219 // Variable is assigned but its value is never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_19
{
public class Program

MODIFY
src/Chapter04/Listing04.27.OutOfScope.cs
src/Chapter04/Listing04.27.OutOfScope.cs
+#pragma warning disable CS0219 // Variable is assigned but its value is never used
+#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_27
{
public class Program
@@ -17,6 +19,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_27
{
// ...
}
+
// Error: message is not in scope:
//System.Console.WriteLine(message);
}

MODIFY
src/Chapter04/Listing04.30.AssignAsBool.cs
src/Chapter04/Listing04.30.AssignAsBool.cs
+#pragma warning disable CS0168 // Variable is declared but never used
+#pragma warning disable CS0219 // Variable is assigned but its value is never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_30
{
public class Program

MODIFY
src/Chapter04/Listing04.48.InputValidation.cs
src/Chapter04/Listing04.48.InputValidation.cs
+#pragma warning disable CS0219 // Variable is assigned but its value is never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_48
{
public class Program

MODIFY
src/Chapter04/Listing04.54.GotoStatements.cs
src/Chapter04/Listing04.54.GotoStatements.cs
+#pragma warning disable CS0219 // Variable is assigned but its value is never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_54
{
public class Program

MODIFY
src/Chapter05/Listing05.10.DeclaringATypeAlias.cs
src/Chapter05/Listing05.10.DeclaringATypeAlias.cs
+#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_10
{
using System;

MODIFY
src/Chapter05/Listing05.11.DeclaringATypeAliasWithTheSameName.cs
src/Chapter05/Listing05.11.DeclaringATypeAliasWithTheSameName.cs
+#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_11
{
// Declare alias Console to refer to SubListing04_09.Console to

MODIFY
src/Chapter05/Listing05.20.MethodsWithOptionalParameters.cs
src/Chapter05/Listing05.20.MethodsWithOptionalParameters.cs
@@ -58,9 +58,23 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_20
private static int CountLines(string file)
{
- return 0;
+ int lineCount = 0;
+ string line;
+ FileStream stream =
+ new FileStream(file, FileMode.Open);
+ StreamReader reader = new StreamReader(stream);
+ line = reader.ReadLine();
+ while (line != null)
+ {
+ if (line.Trim() != "")
+ {
+ lineCount++;
+ }
+ line = reader.ReadLine();
+ }
- // ...
+ reader.Dispose(); // Automatically closes the stream
+ return lineCount;
}
}
}

MODIFY
src/Chapter05/Listing05.25.GeneralCatchBlocks.cs
src/Chapter05/Listing05.25.GeneralCatchBlocks.cs
+#pragma warning disable CS1058 // A previous catch clause already catches all exceptions
+#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_25
{
public class ExceptionHandling

MODIFY
src/Chapter05/Listing05.26.ThrowingAnException.cs
src/Chapter05/Listing05.26.ThrowingAnException.cs
+#pragma warning disable CS1058 // A previous catch clause already catches all exceptions
+#pragma warning disable CS0168 // Variable is declared but never used
+#pragma warning disable CS0162 // Unreachable code detected
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_26
{
using System;

MODIFY
src/Chapter05/Listing05.27.RethrowingAnException.cs
src/Chapter05/Listing05.27.RethrowingAnException.cs
+#pragma warning disable CS0162 // Unreachable code detected
+#pragma warning disable CS1058 // A previous catch clause already catches all exceptions
+#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_27
{
using System;

Addressed warnings in chapters 1-5