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/Chapter02.Tests/Listing02.14.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Main_WriteTriangle()
/ \
/ \
/________\
end";
end";

IntelliTect.TestTools.Console.ConsoleAssert.Expect(
expected, Triangle.Main);
Expand Down
3 changes: 3 additions & 0 deletions src/Chapter02/Listing02.01.SpecifyingLiteralValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ public class Program
{
public static void Main()
{
#region INCLUDE
System.Console.WriteLine(42);

System.Console.WriteLine(1.618034);
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter02/Listing02.02.SpecifyingALiteralDouble.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
System.Console.WriteLine(1.6180339887498948);
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter02/Listing02.03.SpecifyingALiteralDecimal.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
System.Console.WriteLine(1.6180339887498948M);
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter02/Listing02.04.UsingTheDigitSeparator.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
System.Console.WriteLine(9_814_072_356M);
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter02/Listing02.05.ExponentialNotation.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
System.Console.WriteLine(6.023E23F);
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter02/Listing02.06.HexadecimalLiteralValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ public class Program
{
public static void Main()
{
#region INCLUDE
//Display the value 42 using a hexadecimal literal
System.Console.WriteLine(0x002A);
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter02/Listing02.07.BinaryLiteralValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ public class Program
{
public static void Main()
{
#region INCLUDE
// Display the value 42 using a binary literal
System.Console.WriteLine(0b101010);
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ public class Program
{
public static void Main()
{
#region INCLUDE
//Displays "0x2A"
System.Console.WriteLine($"0x{42:X}");
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public class Program
{
public static void Main()
{
#region INCLUDE
// ...
const double number = 1.618033988749895;
double result;
string text;
Expand All @@ -15,6 +17,9 @@ public static void Main()
text = string.Format("{0:R}", number);
result = double.Parse(text);
System.Console.WriteLine($"{result == number}: {result} == {number}");

// ...
#endregion
}
}
}
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 option = "help";

int comparison = string.Compare(option, "/Help", true);
#endregion

System.Console.WriteLine($"{comparison}");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_11
{
#region INCLUDE
public class SingleQuote
{
public static void Main()
{
System.Console.WriteLine('\'');
}
}
#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ public class SingleQuote
{
public static void Main()
{
#region INCLUDE
System.Console.Write('\u003A');

System.Console.WriteLine('\u0029');
#endregion
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_13
{
#region INCLUDE
public class DuelOfWits
{
public static void Main()
Expand All @@ -9,4 +10,5 @@ public static void Main()
System.Console.Write("\n\"Wait 'til I get going!\"\n");
}
}
#endregion
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_14
{
#region INCLUDE
public class Triangle
{
public static void Main()
Expand All @@ -10,7 +11,8 @@ public static void Main()
/ \
/ \
/________\
end");
end");
}
}
#endregion
}
15 changes: 14 additions & 1 deletion src/Chapter02/Listing02.15.UsingStaticDirectives.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_15
{
{
#region INCLUDE
// The using directives allow you to drop the namespace
#region HIGHLIGHT
using static System.Console;
#endregion
public class HeyYou
{
public static void Main()
{
string firstName;
string lastName;

#region HIGHLIGHT
WriteLine("Hey you!");
#endregion

#region HIGHLIGHT
Write("Enter your first name: ");
firstName = ReadLine();
#endregion

Write("Enter your last name: ");
#region HIGHLIGHT
lastName = ReadLine();
#endregion

#region HIGHLIGHT
WriteLine(
#endregion
$"Your full name is {firstName} {lastName}.");
}
}
#endregion
}
4 changes: 4 additions & 0 deletions src/Chapter02/Listing02.16.UsingStringsLengthMember.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_16
{
#region INCLUDE
public class PalindromeLength
{
public static void Main()
Expand All @@ -11,7 +12,10 @@ public static void Main()

System.Console.WriteLine(
$"The palindrome \"{palindrome}\" is"
#region HIGHLIGHT
+ $" {palindrome.Length} characters.");
#endregion
}
}
#endregion
}
4 changes: 4 additions & 0 deletions src/Chapter02/Listing02.17.Error-StringIsImmutable.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_17
{
#region INCLUDE
public class Uppercase
{
public static void Main()
Expand All @@ -9,10 +10,13 @@ public static void Main()
System.Console.Write("Enter text: ");
text = System.Console.ReadLine();

#region HIGHLIGHT
// UNEXPECTED: Does not convert text to uppercase
text.ToUpper();
#endregion

System.Console.WriteLine(text);
}
}
#endregion
}
4 changes: 4 additions & 0 deletions src/Chapter02/Listing02.18.WorkingWithStrings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_18
{
#region INCLUDE
public class Uppercase
{
public static void Main()
Expand All @@ -10,9 +11,12 @@ public static void Main()
text = System.Console.ReadLine();

// Return a new string in uppercase
#region HIGHLIGHT
uppercase = text.ToUpper();
#endregion

System.Console.WriteLine(uppercase);
}
}
#endregion
}
9 changes: 5 additions & 4 deletions src/Chapter02/Listing02.19.AssigningNullToAString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_19
{
public class Program
{
#region INCLUDE
public static void Main()
{
int? age;

//...

// Clear the value of age
age = null;

//...

System.Console.WriteLine($"The age is: {age}");
#region EXCLUDE
System.Console.WriteLine($"The age is: {age}");
#endregion
}
#endregion
}
}
2 changes: 2 additions & 0 deletions src/Chapter02/Listing02.20.ExplicitCastExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ public class Program
{
public static void Main()
{
#region INCLUDE
long longNumber = 50918309109;
int intNumber = (int)longNumber;
#endregion
}
}
}
2 changes: 2 additions & 0 deletions src/Chapter02/Listing02.21.OverflowingAnIntegerValue.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_21
{
#region INCLUDE
public class Program
{
public static void Main()
Expand All @@ -10,4 +11,5 @@ public static void Main()
System.Console.WriteLine(n);
}
}
#endregion
}
6 changes: 6 additions & 0 deletions src/Chapter02/Listing02.22.ACheckedBlockExample.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_22
{
#region INCLUDE
public class Program
{
public static void Main()
{
#region HIGHLIGHT
checked
{
#endregion
// int.MaxValue equals 2147483647
int n = int.MaxValue;
n = n + 1;
System.Console.WriteLine(n);
#region HIGHLIGHT
}
#endregion
}
}
#endregion
}
2 changes: 2 additions & 0 deletions src/Chapter02/Listing02.23.AnUncheckedBlockExample.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_23
{
#region INCLUDE
public class Program
{
public static void Main()
Expand All @@ -13,4 +14,5 @@ public static void Main()
}
}
}
#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ public class Program
{
public static void Main()
{
#region INCLUDE
int intNumber = 31416;
long longNumber = intNumber;
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ public class Program
{
public static void Main()
{
#region INCLUDE
int intNumber = 31416;
long longNumber = (long)intNumber;
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ public class Program
{
public static void Main()
{
#region INCLUDE
string text = "9.11E-31";
float kgElectronMass = float.Parse(text);
#endregion
}
}
}
Loading