Skip to content

Commit 04aa2f0

Browse files
Change Table 3.3 to use file-scoped namespace definitions (#506)
Co-authored-by: Benjamin Michaelis <benjamin@michaelis.net>
1 parent 9b83a27 commit 04aa2f0

10 files changed

+74
-84
lines changed
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// Justification: Only snippets of source code shown for elucidation.
22
#pragma warning disable CS0168 // Variable is declared but never used
33

4-
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03
4+
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03;
5+
6+
public partial class CommonArayCodingErrors
57
{
6-
public partial class CommonArayCodingErrors
8+
// 1.
9+
static public void SquareBracketsOnVariableRatherThanType()
710
{
8-
// 1.
9-
static public void SquareBracketsOnVariableRatherThanType()
10-
{
1111
#if COMPILEERROR
12-
int numbers[];
12+
int numbers[];
1313
#endif // COMPILEERROR
14-
}
1514
}
1615
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
// Justification: Only snippets of source code shown for elucidation.
22
#pragma warning disable CS0168 // Variable is declared but never used
33

4-
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03
4+
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03;
5+
6+
public partial class CommonArrayCodingErrors
57
{
6-
public partial class CommonArayCodingErrors
8+
// 2.
9+
static public void NewKeywordWithDataTypeRequired()
710
{
8-
// 2.
9-
static public void NewKeywordWithDataTypeRequired()
10-
{
1111
#if COMPILEERROR
12-
int[] numbers;
13-
numbers = {42, 84, 168 };
12+
int[] numbers;
13+
numbers = {42, 84, 168 };
1414
#endif // COMPILEERROR
15-
}
1615
}
1716
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
// Justification: Only snippets of source code shown for elucidation.
22
#pragma warning disable CS0168 // Variable is declared but never used
33

4-
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03
4+
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03;
5+
6+
public partial class CommonArayCodingErrors
57
{
6-
public partial class CommonArayCodingErrors
8+
// 3.
9+
static public void ArraySizeCannotBeSpecifiedInDataType()
710
{
8-
// 3.
9-
static public void ArraySizeCannotBeSpecifiedInDataType()
10-
{
1111
#if COMPILEERROR
12-
int[3] numbers =
13-
{ 42, 84, 168 };
12+
int[3] numbers =
13+
{ 42, 84, 168 };
1414
#endif // COMPILEERROR
15-
}
1615
}
1716
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
// Justification: Only snippets of source code shown for elucidation.
22
#pragma warning disable CS0168 // Variable is declared but never used
33

4-
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03
4+
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03;
5+
6+
public partial class CommonArayCodingErrors
57
{
6-
public partial class CommonArayCodingErrors
8+
// 4.
9+
static public void ArraySizeOrInitializerIsRequired()
710
{
8-
// 4.
9-
static public void ArraySizeOrInitializerIsRequired()
10-
{
1111
#if COMPILEERROR
12-
int[] numbers =
13-
new int[];
12+
int[] numbers =
13+
new int[];
1414
#endif // COMPILEERROR
15-
}
1615
}
1716
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
// Justification: Only snippets of source code shown for elucidation.
22
#pragma warning disable CS0168 // Variable is declared but never used
33

4-
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03
4+
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03;
5+
6+
public partial class CommonArayCodingErrors
57
{
6-
public partial class CommonArayCodingErrors
8+
// 5.
9+
static public void ArraySizeWithEmptyInitializer()
710
{
8-
// 5.
9-
static public void ArraySizeWithEmptyInitializer()
10-
{
1111
#if COMPILEERROR
12-
int[] numbers =
13-
new int[3] { };
12+
int[] numbers =
13+
new int[3] { };
1414
#endif // COMPILEERROR
15-
}
1615
}
1716
}
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
// Justification: Only snippets of source code shown for elucidation.
22
#pragma warning disable CS0168 // Variable is declared but never used
33

4-
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03
4+
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03;
5+
6+
public partial class CommonArayCodingErrors
57
{
6-
public partial class CommonArayCodingErrors
8+
// 6.
9+
static public void IndexingOffTheEndOfArray()
710
{
8-
// 6.
9-
static public void IndexingOffTheEndOfArray()
10-
{
11-
int[] numbers =
12-
new int[3];
13-
Console.WriteLine(
14-
numbers[3]);
15-
}
11+
int[] numbers =
12+
new int[3];
13+
Console.WriteLine(
14+
numbers[3]);
1615
}
1716
}
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// Justification: Only snippets of source code shown for elucidation.
22
#pragma warning disable CS0168 // Variable is declared but never used
33

4-
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03
4+
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03;
5+
6+
public partial class CommonArayCodingErrors
57
{
6-
public partial class CommonArayCodingErrors
8+
// 7.
9+
static public void Hat0IsOnePastTheEndOfTheArray1()
710
{
8-
// 7.
9-
static public void Hat0IsOnePastTheEndOfTheArray1()
10-
{
11-
int[] numbers =
12-
new int[3];
13-
numbers[^0] = 42;
14-
}
11+
int[] numbers =
12+
new int[3];
13+
numbers[^0] = 42;
1514
}
1615
}
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
// Justification: Only snippets of source code shown for elucidation.
22
#pragma warning disable CS0168 // Variable is declared but never used
33

4-
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03
4+
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03;
5+
6+
public partial class CommonArayCodingErrors
57
{
6-
public partial class CommonArayCodingErrors
8+
// 8.
9+
static public void LastItemIsLengthMinus1()
710
{
8-
// 8.
9-
static public void LastItemIsLengthMinus1()
10-
{
11-
int[] numbers =
12-
new int[3];
13-
numbers[numbers.Length]
14-
= 42;
15-
}
11+
int[] numbers =
12+
new int[3];
13+
numbers[numbers.Length]
14+
= 42;
1615
}
1716
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
// Justification: Only snippets of source code shown for elucidation.
22
#pragma warning disable CS0168 // Variable is declared but never used
33

4-
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03
4+
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03;
5+
6+
public partial class CommonArayCodingErrors
57
{
6-
public partial class CommonArayCodingErrors
8+
// 9.
9+
static public void MultiDimensionalArrayWithInconsistentSize()
710
{
8-
// 9.
9-
static public void MultiDimensionalArrayWithInconsistentSize()
10-
{
1111
#if COMPILEERROR
12-
int[,] numbers =
13-
{ {42}, {84, 42} };
12+
int[,] numbers =
13+
{ {42}, {84, 42} };
1414
#endif // COMPILEERROR
15-
}
1615
}
1716
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
// Justification: Only snippets of source code shown for elucidation.
22
#pragma warning disable CS0168 // Variable is declared but never used
33

4-
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03
4+
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03;
5+
6+
public partial class CommonArayCodingErrors
57
{
6-
public partial class CommonArayCodingErrors
8+
// 10.
9+
static public void MembersInJaggedArraysMustBeInstantiated()
710
{
8-
// 10.
9-
static public void MembersInJaggedArraysMustBeInstantiated()
10-
{
1111
#if COMPILEERROR
12-
int[][] numbers =
13-
{ {42, 84}, {84, 42} };
12+
int[][] numbers =
13+
{ {42, 84}, {84, 42} };
1414
#endif // COMPILEERROR
15-
}
1615
}
1716
}

0 commit comments

Comments
 (0)