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
2 changes: 1 addition & 1 deletion src/Chapter05.Tests/Listing05.04.DeclaringAMethod.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Main_InputInigoMontoya_WriteFullName()
IntelliTect.TestTools.Console.ConsoleAssert.Expect(view,
() =>
{
Program.Main();
IntroducingMethods.Main();
});
}
}
Expand Down
19 changes: 0 additions & 19 deletions src/Chapter05.Tests/Listing05.14A.Tests.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Chapter05.Tests/Listing05.16.ReturningAReference.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public class ProgramTests
[TestMethod]
public void Main_InputInigoMontoya_WriteFullName()
{
string view = @"image\[*\]=Red
string expected = @"image\[*\]=Red
image\[*\]=Black";

IntelliTect.TestTools.Console.ConsoleAssert.ExpectLike(view,
IntelliTect.TestTools.Console.ConsoleAssert.ExpectLike(expected,
() =>
{
Program.Main();
Expand Down
7 changes: 4 additions & 3 deletions src/Chapter05/Listing05.01.GroupingStatementsIntoMethods.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_01
{
#region INCLUDE
public class LineCount
{
public static void Main()
Expand All @@ -12,7 +13,7 @@ public static void Main()
lineCount = CountLines(files);
DisplayLineCount(lineCount);
}

#region EXCLUDE
private static void DisplayLineCount(int lineCount)
{
throw new System.NotImplementedException();
Expand All @@ -32,7 +33,7 @@ private static void DisplayHelpText()
{
throw new System.NotImplementedException();
}

// ...
#endregion
}
#endregion
}
4 changes: 2 additions & 2 deletions src/Chapter05/Listing05.02.SimpleMethodCall.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_02
{
#region INCLUDE
public class HeyYou
{
public static void Main()
Expand All @@ -10,15 +11,14 @@ public static void Main()
System.Console.WriteLine("Hey you!");

System.Console.Write("Enter your first name: ");
// TODO: Update listing in Manuscript
firstName = System.Console.ReadLine();

System.Console.Write("Enter your last name: ");
// TODO: Update listing in Manuscript
lastName = System.Console.ReadLine();

System.Console.WriteLine(
$"Your full name is { firstName } { lastName }.");
}
}
#endregion
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_03
{
#region INCLUDE
public class Program
{
public static void Main()
{
System.Console.Write("Enter your first name: ");
System.Console.WriteLine("Hello {0}!",
#region HIGHLIGHT
System.Console.ReadLine());
#endregion
}
}
#endregion
}
6 changes: 3 additions & 3 deletions src/Chapter05/Listing05.04.DeclaringAMethod.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_04
{
public class Program
#region INCLUDE
public class IntroducingMethods
{
public static void Main()
{
Expand All @@ -22,7 +23,6 @@ public static void Main()
static string GetUserInput(string prompt)
{
System.Console.Write(prompt);
// TODO: Update listing in Manuscript
return System.Console.ReadLine() ?? string.Empty;
}

Expand All @@ -42,6 +42,6 @@ static string GetInitials(string firstName, string lastName)
{
return $"{ firstName[0] }. { lastName[0] }.";
}

}
#endregion
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_05
{
#region INCLUDE
public class Program
{
#region EXCLUDE
public static void Main()
{
System.Console.WriteLine(MyMethod());
}
#endregion

public static bool MyMethod()
{
Expand All @@ -20,9 +23,12 @@ public static bool MyMethod()
}
}

#region EXCLUDE
private static string ObtainCommand()
{
throw new System.NotImplementedException();
}
#endregion
}
#endregion
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_06
{
#region INCLUDE
public class Program
{
static string GetUserInput(string prompt)
{
System.Console.Write(prompt);
// TODO: Update listing in Manuscript
return System.Console.ReadLine() ?? string.Empty;
}
#region HIGHLIGHT
static (string First, string Last) GetName()
#endregion
{
string firstName, lastName;
firstName = GetUserInput("Enter your first name: ");
Expand All @@ -17,8 +19,11 @@ static string GetUserInput(string prompt)
}
static public void Main()
{
#region HIGHLIGHT
(string First, string Last) name = GetName();
#endregion
System.Console.WriteLine($"Hello { name.First } { name.Last }!");
}
}
#endregion
}
4 changes: 4 additions & 0 deletions src/Chapter05/Listing05.07.UsingDirectiveExample.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_07
{
#region INCLUDE
// The using directive imports all types from the
// specified namespace into the entire file
using System;
Expand All @@ -10,7 +11,10 @@ public static void Main()
{
// No need to qualify Console with System
// because of the using directive above
#region HIGHLIGHT
Console.WriteLine("Hello, my name is Inigo Montoya");
#endregion
}
}
#endregion
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#region INCLUDE
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_08
{
#region HIGHLIGHT
using System;
#endregion

public class HelloWorld
{
public static void Main()
{
// No need to qualify Console with System
// because of the using directive above
#region HIGHLIGHT
Console.WriteLine("Hello, my name is Inigo Montoya");
#endregion
}
}
}
}
#endregion
6 changes: 3 additions & 3 deletions src/Chapter05/Listing05.09.UsingStaticDirective.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_09
{
#region INCLUDE
using static System.Console;

public class HeyYou
Expand All @@ -12,15 +13,14 @@ public static void Main()
WriteLine("Hey you!");

Write("Enter your first name: ");
// TODO: Update listing in Manuscript
firstName = ReadLine() ?? string.Empty;

Write("Enter your last name: ");
// TODO: Update listing in Manuscript
lastName = ReadLine() ?? string.Empty;

WriteLine(
$"Your full name is { firstName } { lastName }.");
}
}

#endregion
}
6 changes: 6 additions & 0 deletions src/Chapter05/Listing05.10.DeclaringATypeAlias.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_10
{
#region INCLUDE
using System;
#region HIGHLIGHT
using System.Threading;
using CountDownTimer = System.Timers.Timer;
#endregion

public class HelloWorld
{
public static void Main()
{
#region HIGHLIGHT
CountDownTimer timer;
#endregion

// ...
}
}
#endregion
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_11
{
#region INCLUDE
using System;
using System.Threading;

#region HIGHLIGHT
// Declare alias Timer to refer to System.Timers.Timer to
// avoid code ambiguity with System.Threading.Timer
using Timer = System.Timers.Timer;
#endregion

public class HelloWorld
{
public static void Main()
{
#region HIGHLIGHT
Timer timer;
#endregion

// ...
}
}
#endregion
}
14 changes: 12 additions & 2 deletions src/Chapter05/Listing05.12.PassingCommandLineArgumentsToMain.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_12
{
// TODO: Update listing in Manuscript
#region INCLUDE
using System;
using System.Net;

public class Program
{
#region HIGHLIGHT
public static int Main(string[] args)
#endregion
{
#region HIGHLIGHT
int result;
switch(args.Length)
#endregion
{
default:
// Exactly two arguments must be specified; give an error
Expand All @@ -22,12 +26,18 @@ public static int Main(string[] args)
break;
case 2:
WebClient webClient = new WebClient();
#region HIGHLIGHT
webClient.DownloadFile(args[0], args[1]);
#endregion
result = 0;
#region HIGHLIGHT
break;
#endregion
}

#region HIGHLIGHT
return result;
#endregion
}
}
#endregion
}
2 changes: 2 additions & 0 deletions src/Chapter05/Listing05.13.PassingVariablesByValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_13
{
using System;

#region INCLUDE
public class Program
{
public static void Main()
Expand All @@ -28,4 +29,5 @@ static string Combine(
return path;
}
}
#endregion
}
6 changes: 6 additions & 0 deletions src/Chapter05/Listing05.14.PassingVariablesByReference.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_14
{
#region INCLUDE
public class Program
{
public static void Main()
{
// ...
string first = "hello";
string second = "goodbye";
#region HIGHLIGHT
Swap(ref first, ref second);
#endregion

System.Console.WriteLine(
$@"first = ""{ first }"", second = ""{ second }""");
// ...
}

#region HIGHLIGHT
static void Swap(ref string x, ref string y)
#endregion
{
string temp = x;
x = y;
y = temp;
}
}
#endregion
}
Loading