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
5 changes: 2 additions & 3 deletions src/Chapter03/Chapter03.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Import Project="..\Chapter.props" />
<ItemGroup>
<Compile Remove="Listing03.02.DereferencingAnUnassignedVariable.cs" />
<Compile Remove="Listing03.03.EnablingNullableProjectWide-PlaceHolderFile.cs" />
<Compile Remove="Listing03.03.EnablingNullableProjectWide.cs" />
<Compile Remove="Listing03.06.TheCSharpEquivalentOfCompilerGeneratedCILCodeForAValueTupleReturn.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -25,8 +25,7 @@
<None Include="Listing03.02.DereferencingAnUnassignedVariable.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Listing03.03.EnablingNullableProjectWide-PlaceHolderFile.cs" />
<None Include="Listing03.03.EnablingNullableProjectWide.csproj" />
<None Include="Listing03.03.EnablingNullableProjectWide.cs" />
<None Include="Listing03.06.TheCSharpEquivalentOfCompilerGeneratedCILCodeForAValueTupleReturn.cs" />
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions src/Chapter03/Listing03.01.CheckingForNull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_01
{
public class Program
{
#region INCLUDE
public static void Main(string[] args)
{
int? number = null;

// ...
if(args.Length>0)
#region EXCLUDE
if (args.Length>0)
{
number = args[0].Length;
}

#endregion
if (number is null)
{
System.Console.WriteLine(
Expand All @@ -22,8 +22,8 @@ public static void Main(string[] args)
System.Console.WriteLine(
$"'number' doubled is { number * 2 }.");
}

}
#endregion
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
//{
public class Program
{
#region INCLUDE
#nullable enable
public static void Main()
{
string? text;
// ...

// Compile Error: Use of unassigned local variable 'text'
System.Console.WriteLine(text.Length);
}
#endregion
}
//}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
#region INCLUDE
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
#endregion
2 changes: 2 additions & 0 deletions src/Chapter03/Listing03.04.WorkingWithStrings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_04
{
#region INCLUDE
public class Uppercase
{
public static void Main()
Expand All @@ -13,4 +14,5 @@ public static void Main()
System.Console.WriteLine(uppercase);
}
}
#endregion
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_05
{
#region INCLUDE
public class Program
{
public static void Main()
Expand All @@ -17,4 +18,5 @@ public static void Main()
$"{patent2.Title} ({patent2.YearOfPublication})");
}
}
#endregion
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_06
{
namespace Chapter03
#region INCLUDE
[return: System.Runtime.CompilerServices.TupleElementNames(new string[] { "First", "Second" })]
public System.ValueTuple<string, string> ParseNames(string fullName)
{
[return: System.Runtime.CompilerServices.TupleElementNames(new string[] { "First", "Second" })]
public System.ValueTuple<string, string> ParseNames(string fullName)
{
// ...
}

// ...
}

#endregion
}
2 changes: 2 additions & 0 deletions src/Chapter03/Listing03.07.DeclaringAnArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public class Program
{
public static void Main()
{
#region INCLUDE
string[] languages;
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter03/Listing03.08.DeclaringATwoDimensionalArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ public class Program
{
public static void Main()
{
#region INCLUDE
// | |
// ---+---+---
// | |
// ---+---+---
// | |
int[,] cells;
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter03/Listing03.09.ArrayDeclarationWithAssignment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ public class Program
{
public static void Main()
{
#region INCLUDE
string[] languages = { "C#", "COBOL", "Java",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ public class Program
{
public static void Main()
{
#region INCLUDE
string[] languages;
languages = new string[] { "C#", "COBOL", "Java",
languages = new string[]{ "C#", "COBOL", "Java",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ public class Program
{
public static void Main()
{
string[] languages = new string[] {
#region INCLUDE
string[] languages = new string[]{
"C#", "COBOL", "Java",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ public class Program
{
public static void Main()
{
string[] languages = new string[9] {
#region INCLUDE
string[] languages = new string[9]{
"C#", "COBOL", "Java",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript" };
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter03/Listing03.13.AssigningWithoutLiteralValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ public class Program
{
public static void Main()
{
#region INCLUDE
string[] languages = new string[9];
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter03/Listing03.14.DefiningTheArraySizeAtRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ public class Program
{
public static void Main()
{
#region INCLUDE
string[] groceryList;
System.Console.Write("How many items on the list? ");
int size = int.Parse(System.Console.ReadLine());
groceryList = new string[size];
// ...
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter03/Listing03.15.DeclaringATwoDimensionalArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ public class Program
{
public static void Main()
{
#region INCLUDE
int[,] cells = new int[3,3];
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ public class Program
{
public static void Main()
{
#region INCLUDE
int[,] cells = {
{1, 0, 2},
{1, 2, 0},
{1, 2, 1}
};
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ public class Program
{
public static void Main()
{
#region INCLUDE
// ERROR: Each dimension must be consistently sized
#region EXCLUDE
/*
#endregion
int[,] cells = {
{1, 0, 2, 0},
{1, 2, 0},
{1, 2},
{1}
};
#region EXCLUDE
*/
#endregion
#endregion
}
}
}
38 changes: 25 additions & 13 deletions src/Chapter03/Listing03.18.InitializingAThreeDimensionalArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@ public class Program
{
public static void Main()
{
#region INCLUDE
bool[, ,] cells;
cells = new bool[2, 3, 3]
cells = new bool[2, 3, 3]
{
// Player 1 moves
{ // X | |
{true, false, false}, // ---+---+---
{true, false, false}, // X | |
{true, false, true} // ---+---+---
}, // X | | X
// Player 2 moves
{ // | | O
{false, false, true}, // ---+---+---
{false, true, false}, // | O |
{false, true, true} // ---+---+---
} // | O |
// Player 1 moves
// X | |
// ---+---+---
// X | |
// ---+---+---
// X | | X
{
{true, false, false},
{true, false, false},
{true, false, true}
},
// Player 2 moves
// | | O
// ---+---+---
// | O |
// ---+---+---
// | O |
{
{false, false, true},
{false, true, false},
{false, true, true}
}
};
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter03/Listing03.19.InitializingAJaggedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ public class Program
{
public static void Main()
{
#region INCLUDE
int[][] cells = {
new int[] {1, 0, 2, 0},
new int[] {1, 2, 0},
new int[] {1, 2},
new int[] {1}
};
#endregion
}
}
}
8 changes: 5 additions & 3 deletions src/Chapter03/Listing03.20.DeclaringAndAccessingAnArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ public class Program
{
public static void Main()
{
string[] languages = new string[] {
#region INCLUDE
string[] languages = new string[9]{
"C#", "COBOL", "Java",
"C++", "TypeScript", "Visual Basic",
"Python", "Lisp", "JavaScript"};
// Retrieve fifth item in languages array (TypeScript)
string language = languages[4];
// Write TypeScript
// Write "TypeScript"
System.Console.WriteLine(language);
// Retrieve second item from the end (Python)
language = languages[^3];
// Write Python
// Write "Python"
System.Console.WriteLine(language);
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class Program
{
public static void Main()
{
#region INCLUDE
string[] languages = new string[] {
"C#", "COBOL", "Java",
"C++", "TypeScript", "Visual Basic",
Expand All @@ -14,6 +15,7 @@ public static void Main()
languages[3] = languages[2];
// Assign language to location of "Java"
languages[2] = language;
#endregion
}
}
}
Loading