Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Chapter03/Listing03.01.CheckingForNull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void Main(string[] args)
{
number = args[0].Length;
}
#endregion
#endregion EXCLUDE
if (number is null)
{
System.Console.WriteLine(
Expand All @@ -23,7 +23,7 @@ public static void Main(string[] args)
$"'number' doubled is { number * 2 }.");
}
}
#endregion
#endregion INCLUDE
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public static void Main()
// Compile Error: Use of unassigned local variable 'text'
System.Console.WriteLine(text.Length);
}
#endregion
}
#endregion INCLUDE
}
//}
2 changes: 1 addition & 1 deletion src/Chapter03/Listing03.03.EnablingNullableProjectWide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
#endregion
#endregion INCLUDE
2 changes: 1 addition & 1 deletion src/Chapter03/Listing03.04.WorkingWithStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public static void Main()
System.Console.WriteLine(uppercase);
}
}
#endregion
#endregion INCLUDE
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ public static void Main()
$"{patent2.Title} ({patent2.YearOfPublication})");
}
}
#endregion
#endregion INCLUDE
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public System.ValueTuple<string, string> ParseNames(string fullName)
{
// ...
}
#endregion
#endregion INCLUDE
}
4 changes: 2 additions & 2 deletions src/Chapter03/Listing03.07.DeclaringAnArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static void Main()
{
#region INCLUDE
string[] languages;
#endregion
#endregion INCLUDE
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void Main()
// ---+---+---
// | |
int[,] cells;
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static void Main()
string[] languages = { "C#", "COBOL", "Java",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static void Main()
languages = new string[]{ "C#", "COBOL", "Java",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static void Main()
"C#", "COBOL", "Java",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static void Main()
"C#", "COBOL", "Java",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static void Main()
{
#region INCLUDE
string[] languages = new string[9];
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void Main()
int size = int.Parse(System.Console.ReadLine());
groceryList = new string[size];
// ...
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static void Main()
{
#region INCLUDE
int[,] cells = new int[3,3];
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void Main()
{1, 2, 0},
{1, 2, 1}
};
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static void Main()
};
#region EXCLUDE
*/
#endregion
#endregion
#endregion EXCLUDE
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void Main()
{false, true, true}
}
};
#endregion
#endregion INCLUDE
}
}
}
2 changes: 1 addition & 1 deletion src/Chapter03/Listing03.19.InitializingAJaggedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void Main()
new int[] {1, 2},
new int[] {1}
};
#endregion
#endregion INCLUDE
}
}
}
2 changes: 1 addition & 1 deletion src/Chapter03/Listing03.20.DeclaringAndAccessingAnArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void Main()
language = languages[^3];
// Write "Python"
System.Console.WriteLine(language);
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void Main()
languages[3] = languages[2];
// Assign language to location of "Java"
languages[2] = language;
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void Main()
};
// Set the winning tic-tac-toe move to be player 1
cells[1, 0] = 1;
#endregion
#endregion INCLUDE
}
}
}
2 changes: 1 addition & 1 deletion src/Chapter03/Listing03.23.DeclaringAJaggedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void Main()

cells[1][0] = 1;
// ...
#endregion
#endregion INCLUDE
}
}
}
2 changes: 1 addition & 1 deletion src/Chapter03/Listing03.24.RetrievingTheLengthOfAnArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static void Main()
#region INCLUDE
System.Console.WriteLine(
$"There are {languages.Length} languages in the array.");
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void Main()
// RUNTIME ERROR: index out of bounds - should
// be 8 for the last element
languages[4] = languages[9];
#endregion
#endregion INCLUDE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void Main()
string[] languages = new string[9];
// ...
languages[4] = languages[languages.Length - 1];
#endregion
#endregion INCLUDE
}
}
}
2 changes: 1 addition & 1 deletion src/Chapter03/Listing03.27.Slicing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void Main()
// C#, COBOL, Java, C++, TypeScript, Swift, Python, Lisp, JavaScript
string.Join(", ", languages[0..^0]) // Python, Lisp, JavaScript
}");
#endregion
#endregion INCLUDE
}
}
}
10 changes: 5 additions & 5 deletions src/Chapter03/Listing03.28.AdditionalArrayMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public static void Main()

#region HIGHLIGHT
System.Array.Sort(languages);
#endregion
#endregion HIGHLIGHT

string searchString = "COBOL";
#region HIGHLIGHT
int index = System.Array.BinarySearch(
languages, searchString);
#endregion
#endregion HIGHLIGHT
System.Console.WriteLine(
"The wave of the future, "
+ $"{ searchString }, is at index { index }.");
Expand All @@ -32,20 +32,20 @@ public static void Main()
$"{ languages[0],-20 }\t{ languages[^1],-20 }");
#region HIGHLIGHT
System.Array.Reverse(languages);
#endregion
#endregion HIGHLIGHT
System.Console.WriteLine(
$"{ languages[0],-20 }\t{ languages[^1],-20 }");
// Note this does not remove all items from the array
// Rather it sets each item to the type's default value
#region HIGHLIGHT
System.Array.Clear(languages, 0, languages.Length);
#endregion
#endregion HIGHLIGHT
System.Console.WriteLine(
$"{ languages[0],-20 }\t{ languages[^1],-20 }");
System.Console.WriteLine(
$"After clearing, the array size is: { languages.Length }");
}
}
#endregion
#endregion INCLUDE
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static void Main()
cells = new bool[2, 3, 3];
System.Console.WriteLine(cells.GetLength(0)); // Displays 2
System.Console.WriteLine(cells.Rank); // Displays 3
#endregion
#endregion INCLUDE
}
}
}
2 changes: 1 addition & 1 deletion src/Chapter03/Listing03.30.LookingForCommandlineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public static void Main(string[] args)
// This parameter is an option
}
}
#endregion
#endregion INCLUDE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public static void Main(string[] args)
// This parameter is an option
}
}
#endregion
#endregion INCLUDE
}
}
8 changes: 4 additions & 4 deletions src/Chapter03/Listing03.32.ReversingAString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ public static void Main()
#region HIGHLIGHT
// Convert to an array
temp = reverse.ToCharArray();
#endregion
#endregion HIGHLIGHT

#region HIGHLIGHT
// Reverse the array
System.Array.Reverse(temp);
#endregion
#endregion HIGHLIGHT

// Convert the array back to a string and
// check if reverse string is the same
if(reverse == new string(temp))
if (reverse == new string(temp))
{
System.Console.WriteLine(
$"\"{palindrome}\" is a palindrome.");
Expand All @@ -39,5 +39,5 @@ public static void Main()
}
}
}
#endregion
#endregion INCLUDE
}