Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Chapters 2/3/4 with corrections #181

Merged
merged 9 commits into from
Dec 20, 2021
6 changes: 6 additions & 0 deletions Errata.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Salim Gangji | 1 | 12 | First paragraph: For a single
Pieter Le Roux | 1 | 31 | Last Line: Table 1.2 shows four different C# comment types. The program in <s>Listing 1.18</s> Listing 1.19 includes two of these.
Benjamin Michaelis | 1 | 31 | Last Line: Table 1.2 shows four different C# comment types. The program in Listing 1.19 includes <s>two</s>three of these.
Salim Gangji | 2 | 51 | Output 2.3: <s>1.61803398874985</s> 1.618033988749895
Alden Bansemer | 2 | 55 | Listing 2.9: <s>`result == number`</s> `{result} == {number}`. Output 2.7: <s>`result == number`</s> `1.61803398874989 == 1.61803398874989`.
Alden Bansemer | 3 | 89 | Listing 3.4: Changed <s>`class 3.2->3.Uppercase`</s> to match source `class Uppercase`.
Alden Bansemer | 3 | 113 | Output 3.2: `TypeScript` replaced with `Visual Basic` as last element in sorted array and first element in the reversed, sorted array.
Alden Bansemer | 3 | 114 | Output 3.3: Added missing second line of output: `3`.
Alden Bansemer | 4 | 129 | Listing 4.7: Removed Trace.Assert to match codebase. Removed example #4, float converted to double now matches the double.
Alden Bansemer | 4 | 130 | Output 4.6: Updated results of Listing 4.7 to remove <s>`4.20000006258488 != 4.20000028610229`</s>.
Pieter Le Roux | 5 | 215 | Output 5.4: ERROR: You must specify the URL <s>to be downloaded</s> and the file name **Usage:** Downloader.exe <URL> <TargetFileName>
Pieter Le Roux | 6 | 285 | Last Line in second paragraph: "DO use nameof for the paramName argument passed into exceptions like Argument<s>Null</s>Exception and ArgumentNullException that take such a parameter. For more information, see Chapter 18."
Pieter Le Roux | 7 | 359 | return <s>@</s>$"FirstName: { FirstName + NewLine }" + $"LastName: { LastName + NewLine }"+ $"Address: { Address + NewLine }";
Expand Down
4 changes: 2 additions & 2 deletions src/Chapter02/Listing02.15.UsingStaticDirectives.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_15
{
using static System.Console;
class HeyYou
public class HeyYou
{
static void Main()
public static void Main()
{
string firstName;
string lastName;
Expand Down
2 changes: 1 addition & 1 deletion src/Chapter02/Listing02.17.Error-StringIsImmutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static void Main()
System.Console.Write("Enter text: ");
text = System.Console.ReadLine();

//UNEXPECTED: Does not convert text to uppercase
// UNEXPECTED: Does not convert text to uppercase
text.ToUpper();

System.Console.WriteLine(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class Program
public static void Main()
{
string[] languages = { "C#", "COBOL", "Java",
"C++", "TypeScript", "Pascal",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static void Main()
{
string[] languages;
languages = new string[] { "C#", "COBOL", "Java",
"C++", "TypeScript", "Pascal",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static void Main()
{
string[] languages = new string[] {
"C#", "COBOL", "Java",
"C++", "TypeScript", "Pascal",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static void Main()
{
string[] languages = new string[9] {
"C#", "COBOL", "Java",
"C++", "TypeScript", "Pascal",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Chapter03/Listing03.20.DeclaringAndAccessingAnArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static void Main()
{
string[] languages = new string[] {
"C#", "COBOL", "Java",
"C++", "TypeScript", "Pascal",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript"};
// Retrieve fifth item in languages array (TypeScript)
string language = languages[4];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static void Main()
{
string[] languages = new string[] {
"C#", "COBOL", "Java",
"C++", "TypeScript", "Pascal",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
// Save "C++" to variable called language
string language = languages[3];
Expand Down
13 changes: 4 additions & 9 deletions src/Chapter03/Listing03.27.Slicing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static void Main()
{
string[] languages = new string[] {
"C#", "COBOL", "Java",
"C++", "TypeScript", "Pascal",
"C++", "TypeScript", "Visual Basic",
BenjaminMichaelis marked this conversation as resolved.
Show resolved Hide resolved
"Python", "Lisp", "JavaScript"};

System.Console.WriteLine($@" 0..3: {
Expand All @@ -16,7 +16,7 @@ public static void Main()
string.Join(", ", languages[^3..^0]) // Python, Lisp, JavaScript
}");
System.Console.WriteLine($@" 3..^3: {
string.Join(", ", languages[3..^3]) // C++, TypeScript, Pascal
string.Join(", ", languages[3..^3]) // C++, TypeScript, Visual Basic
}");
System.Console.WriteLine($@" ..^6: {
string.Join(", ", languages[..^6]) // C#, COBOL, Java
Expand All @@ -25,16 +25,11 @@ public static void Main()
string.Join(", ", languages[6..]) // Python, Lisp, JavaScript
}");
System.Console.WriteLine($@" ..: {
// C#, COBOL, Java, C++, TypeScript, Pascal, Python, Lisp, JavaScript
// C#, COBOL, Java, C++, TypeScript, Visual Basic, Python, Lisp, JavaScript
string.Join(", ", languages[..]) // Python, Lisp, JavaScript
}");





System.Console.WriteLine($@" ..: {
// C#, COBOL, Java, C++, TypeScript, Pascal, Python, Lisp, JavaScript
// C#, COBOL, Java, C++, TypeScript, Visual Basic, Python, Lisp, JavaScript
string.Join(", ", languages[0..^0]) // Python, Lisp, JavaScript
}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Chapter03/Listing03.28.AdditionalArrayMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static void Main()
{
string[] languages = new string[]{
"C#", "COBOL", "Java",
"C++", "TypeScript", "Pascal",
"C++", "TypeScript", "Visual Basic",
BenjaminMichaelis marked this conversation as resolved.
Show resolved Hide resolved
"Python", "Lisp", "JavaScript"};

System.Array.Sort(languages);
Expand Down
2 changes: 1 addition & 1 deletion src/Chapter04/Listing04.02.Negative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class Program
public static void Main()
{
//National Debt to the Penny
decimal debt = -18125876697430.99M;
decimal debt = -28382607800141.79M;
BenjaminMichaelis marked this conversation as resolved.
Show resolved Hide resolved

System.Console.WriteLine(debt);
}
Expand Down
14 changes: 4 additions & 10 deletions src/Chapter04/Listing04.07.UnexpectedInequality.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,19 @@ public static void Main()
System.Console.WriteLine(
$"(float){(float)decimalNumber}M != {floatNumber}F");

// Removing - float converted to double now matches the double
//Trace.Assert(doubleNumber1 != (double)floatNumber);
//// 4. Displays: 4.20000028610229 != 4.20000028610229
//System.Console.WriteLine(
// $"{doubleNumber1} != {(double)floatNumber}");

// 5. Displays: 4.200000286102295 != 4.2
// 4. Displays: 4.200000286102295 != 4.2
System.Console.WriteLine(
$"{doubleNumber1} != {doubleNumber2}");

// 6. Displays: 4.2000003F != 4.2D
// 5. Displays: 4.2000003F != 4.2D
System.Console.WriteLine(
$"{floatNumber}F != {doubleNumber2}D");

// 7. Displays: 4.199999809265137 != 4.2
// 6. Displays: 4.199999809265137 != 4.2
System.Console.WriteLine(
$"{(double)4.2F} != {4.2D}");

// 8. Displays: 4.2F != 4.2D
// 7. Displays: 4.2F != 4.2D
System.Console.WriteLine(
$"{4.2F}F != {4.2D}D");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Chapter04/Listing04.18.ComparingPrefixAndPostfix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public static void Main()
// Displays 123, 124, 125
System.Console.WriteLine($"{x++}, {x++}, {x}");
// x now contains the value 125
// Displays 126, 127, 128
// Displays 126, 127, 127
System.Console.WriteLine($"{++x}, {++x}, {x}");
// x now contains the value 128
// x now contains the value 127
}
}
}
2 changes: 1 addition & 1 deletion src/Shared/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void Main(string[] args)
{
input = ParseListingName(input);

Regex reg = new Regex($"{input}\\.+");
Regex reg = new Regex($"Listing{input}\\.+");

IEnumerable<Type?> targets = assembly.GetTypes().Where(type =>
{
Expand Down