Skip to content

Commit

Permalink
Add code solutions for Ch1-6
Browse files Browse the repository at this point in the history
  • Loading branch information
markjprice committed Jul 23, 2024
1 parent 93dbd00 commit d3d6f34
Show file tree
Hide file tree
Showing 136 changed files with 4,860 additions and 2 deletions.
10 changes: 10 additions & 0 deletions code/Chapter01-vscode/AboutMyEnvironment/AboutMyEnvironment.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
12 changes: 12 additions & 0 deletions code/Chapter01-vscode/AboutMyEnvironment/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace AboutMyEnvironment;

class Program
{
static void Main(string[] args)
{
Console.WriteLine(Environment.CurrentDirectory);
Console.WriteLine(Environment.OSVersion.VersionString);
Console.WriteLine("Namespace: {0}",
typeof(Program).Namespace ?? "<null>");
}
}
28 changes: 28 additions & 0 deletions code/Chapter01-vscode/Chapter01.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloCS", "HelloCS\HelloCS.csproj", "{DE03EF41-5093-4F2C-8ACA-C36AB29C1FDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AboutMyEnvironment", "AboutMyEnvironment\AboutMyEnvironment.csproj", "{24FAC3DD-5110-4837-93BC-5FDF433876F7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DE03EF41-5093-4F2C-8ACA-C36AB29C1FDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE03EF41-5093-4F2C-8ACA-C36AB29C1FDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE03EF41-5093-4F2C-8ACA-C36AB29C1FDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE03EF41-5093-4F2C-8ACA-C36AB29C1FDC}.Release|Any CPU.Build.0 = Release|Any CPU
{24FAC3DD-5110-4837-93BC-5FDF433876F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24FAC3DD-5110-4837-93BC-5FDF433876F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{24FAC3DD-5110-4837-93BC-5FDF433876F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{24FAC3DD-5110-4837-93BC-5FDF433876F7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions code/Chapter01-vscode/HelloCS/HelloCS.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
7 changes: 7 additions & 0 deletions code/Chapter01-vscode/HelloCS/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, C#!");

string name = typeof(Program).Namespace ?? "<null>";
Console.WriteLine($"Namespace: {name}");

throw new Exception();
10 changes: 10 additions & 0 deletions code/Chapter01/AboutMyEnvironment/AboutMyEnvironment.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
13 changes: 13 additions & 0 deletions code/Chapter01/AboutMyEnvironment/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AboutMyEnvironment
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine(Environment.CurrentDirectory);
Console.WriteLine(Environment.OSVersion.VersionString);
Console.WriteLine("Namespace: {0}",
typeof(Program).Namespace ?? "<null>");
}
}
}
28 changes: 28 additions & 0 deletions code/Chapter01/Chapter01.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloCS", "HelloCS\HelloCS.csproj", "{315C4F55-36D1-458C-8C74-BCD780D4FE2D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AboutMyEnvironment", "AboutMyEnvironment\AboutMyEnvironment.csproj", "{9BED26C1-27AB-4DA4-A6D9-43533AC08258}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{315C4F55-36D1-458C-8C74-BCD780D4FE2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{315C4F55-36D1-458C-8C74-BCD780D4FE2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{315C4F55-36D1-458C-8C74-BCD780D4FE2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{315C4F55-36D1-458C-8C74-BCD780D4FE2D}.Release|Any CPU.Build.0 = Release|Any CPU
{9BED26C1-27AB-4DA4-A6D9-43533AC08258}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9BED26C1-27AB-4DA4-A6D9-43533AC08258}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BED26C1-27AB-4DA4-A6D9-43533AC08258}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BED26C1-27AB-4DA4-A6D9-43533AC08258}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions code/Chapter01/HelloCS/HelloCS.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
8 changes: 8 additions & 0 deletions code/Chapter01/HelloCS/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, C#!");

string name = typeof(Program).Namespace ?? "<null>";
Console.WriteLine($"Namespace: {name}");

throw new Exception();
int z;
14 changes: 14 additions & 0 deletions code/Chapter02/Arguments/Arguments.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Using Include="System.Console" Static="true" />
</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions code/Chapter02/Arguments/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
WriteLine($"There are {args.Length} arguments.");

foreach (string arg in args)
{
WriteLine(arg);
}

if (args.Length < 3)
{
WriteLine("You must specify two colors and cursor size, e.g.");
WriteLine("dotnet run red yellow 50");
return; // Stop running.
}

ForegroundColor = (ConsoleColor)Enum.Parse(
enumType: typeof(ConsoleColor),
value: args[0], ignoreCase: true);

BackgroundColor = (ConsoleColor)Enum.Parse(
enumType: typeof(ConsoleColor),
value: args[1], ignoreCase: true);

try
{
CursorSize = int.Parse(args[2]);
}
catch (PlatformNotSupportedException)
{
WriteLine("The current platform does not support changing the size of the cursor.");
}
8 changes: 8 additions & 0 deletions code/Chapter02/Arguments/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Arguments": {
"commandName": "Project",
"commandLineArgs": "red yellow 50"
}
}
}
14 changes: 14 additions & 0 deletions code/Chapter02/AsyncConsole/AsyncConsole.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Using Include="System.Console" Static="true" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions code/Chapter02/AsyncConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HttpClient client = new();

HttpResponseMessage response =
await client.GetAsync("http://www.apple.com/");

WriteLine("Apple's home page has {0:N0} bytes.",
response.Content.Headers.ContentLength);
61 changes: 61 additions & 0 deletions code/Chapter02/Chapter02.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vocabulary", "Vocabulary\Vocabulary.csproj", "{EADDBE7F-7DBC-48E9-9055-90C14F10B0DA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Numbers", "Numbers\Numbers.csproj", "{CE582F72-50C4-4805-AFDE-FBDCDB61C8C7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Variables", "Variables\Variables.csproj", "{72EE31A5-6F88-43C3-8711-591BE6A1DB11}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Formatting", "Formatting\Formatting.csproj", "{C17A0DB7-9EB4-460A-8812-BB4EC5A58D82}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arguments", "Arguments\Arguments.csproj", "{2B4BD7E9-62F1-4999-AFF3-69BCBDC7BE71}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsyncConsole", "AsyncConsole\AsyncConsole.csproj", "{60F9BB41-04FA-4960-91AF-05B82E4EAE06}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Exercise_Numbers", "Exercise_Numbers\Exercise_Numbers.csproj", "{CE53DADE-75C6-4BE2-A0C7-E04BBABE773F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EADDBE7F-7DBC-48E9-9055-90C14F10B0DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EADDBE7F-7DBC-48E9-9055-90C14F10B0DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EADDBE7F-7DBC-48E9-9055-90C14F10B0DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EADDBE7F-7DBC-48E9-9055-90C14F10B0DA}.Release|Any CPU.Build.0 = Release|Any CPU
{CE582F72-50C4-4805-AFDE-FBDCDB61C8C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE582F72-50C4-4805-AFDE-FBDCDB61C8C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE582F72-50C4-4805-AFDE-FBDCDB61C8C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE582F72-50C4-4805-AFDE-FBDCDB61C8C7}.Release|Any CPU.Build.0 = Release|Any CPU
{72EE31A5-6F88-43C3-8711-591BE6A1DB11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72EE31A5-6F88-43C3-8711-591BE6A1DB11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72EE31A5-6F88-43C3-8711-591BE6A1DB11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72EE31A5-6F88-43C3-8711-591BE6A1DB11}.Release|Any CPU.Build.0 = Release|Any CPU
{C17A0DB7-9EB4-460A-8812-BB4EC5A58D82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C17A0DB7-9EB4-460A-8812-BB4EC5A58D82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C17A0DB7-9EB4-460A-8812-BB4EC5A58D82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C17A0DB7-9EB4-460A-8812-BB4EC5A58D82}.Release|Any CPU.Build.0 = Release|Any CPU
{2B4BD7E9-62F1-4999-AFF3-69BCBDC7BE71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B4BD7E9-62F1-4999-AFF3-69BCBDC7BE71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B4BD7E9-62F1-4999-AFF3-69BCBDC7BE71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B4BD7E9-62F1-4999-AFF3-69BCBDC7BE71}.Release|Any CPU.Build.0 = Release|Any CPU
{60F9BB41-04FA-4960-91AF-05B82E4EAE06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{60F9BB41-04FA-4960-91AF-05B82E4EAE06}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60F9BB41-04FA-4960-91AF-05B82E4EAE06}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60F9BB41-04FA-4960-91AF-05B82E4EAE06}.Release|Any CPU.Build.0 = Release|Any CPU
{CE53DADE-75C6-4BE2-A0C7-E04BBABE773F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE53DADE-75C6-4BE2-A0C7-E04BBABE773F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE53DADE-75C6-4BE2-A0C7-E04BBABE773F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE53DADE-75C6-4BE2-A0C7-E04BBABE773F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F629F151-457A-448E-AFB1-4017F941BD81}
EndGlobalSection
EndGlobal
15 changes: 15 additions & 0 deletions code/Chapter02/Exercise_Numbers/Exercise_Numbers.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<Using Include="System.Console" Static="true" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions code/Chapter02/Exercise_Numbers/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
string rowSeparator = new string('-', count: 104);
WriteLine(rowSeparator);
WriteLine($"Type {"Byte(s) of memory",-4} {"Min",32} {"Max",45}");
WriteLine(rowSeparator);
WriteLine($"sbyte {sizeof(sbyte),-4} {sbyte.MinValue,45} {sbyte.MaxValue,45}");
WriteLine($"byte {sizeof(byte),-4} {byte.MinValue,45} {byte.MaxValue,45}");
WriteLine($"short {sizeof(short),-4} {short.MinValue,45} {short.MaxValue,45}");
WriteLine($"ushort {sizeof(ushort),-4} {ushort.MinValue,45} {ushort.MaxValue,45}");
WriteLine($"int {sizeof(int),-4} {int.MinValue,45} {int.MaxValue,45}");
WriteLine($"uint {sizeof(uint),-4} {uint.MinValue,45} {uint.MaxValue,45}");
WriteLine($"long {sizeof(long),-4} {long.MinValue,45} {long.MaxValue,45}");
WriteLine($"ulong {sizeof(ulong),-4} {ulong.MinValue,45} {ulong.MaxValue,45}");
unsafe
{
WriteLine($"Int128 {sizeof(Int128),-4} {Int128.MinValue,45} {Int128.MaxValue,45}");
WriteLine($"UInt128 {sizeof(UInt128),-4} {UInt128.MinValue,45} {UInt128.MaxValue,45}");
WriteLine($"Half {sizeof(Half),-4} {Half.MinValue,45} {Half.MaxValue,45}");
}
WriteLine($"float {sizeof(float),-4} {float.MinValue,45} {float.MaxValue,45}");
WriteLine($"double {sizeof(double),-4} {double.MinValue,45} {double.MaxValue,45}");
WriteLine($"decimal {sizeof(decimal),-4} {decimal.MinValue,45} {decimal.MaxValue,45}");
WriteLine(rowSeparator);
14 changes: 14 additions & 0 deletions code/Chapter02/Formatting/Formatting.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup Label="Simplify console app">
<Using Include="System.Console" Static="true" />
</ItemGroup>

</Project>
Loading

0 comments on commit d3d6f34

Please sign in to comment.