mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-01-03 06:49:55 +01:00
Initial commit
This commit is contained in:
parent
7fa1000b05
commit
143e708681
|
|
@ -67,7 +67,7 @@
|
|||
case 11: // special cases for 11th to 13th
|
||||
case 12:
|
||||
case 13:
|
||||
return $"{number}th";
|
||||
return $"{number:N0}th";
|
||||
default:
|
||||
int lastDigit = number % 10;
|
||||
|
||||
|
|
@ -79,13 +79,13 @@
|
|||
_ => "th"
|
||||
};
|
||||
|
||||
return $"{number}{suffix}";
|
||||
return $"{number:N0}{suffix}";
|
||||
}
|
||||
}
|
||||
|
||||
static void RunCardinalToOrdinal()
|
||||
{
|
||||
for (int number = 1; number <= 1030; number++)
|
||||
for (int number = 1; number <= 1500; number++)
|
||||
{
|
||||
Write($"{CardinalToOrdinal(number)} ");
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@
|
|||
|
||||
static void RunFactorial()
|
||||
{
|
||||
for (int i = -2; i <= 14; i++)
|
||||
for (int i = -2; i <= 15; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -127,7 +127,7 @@
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLine($"{ex.GetType()}: {ex.Message}.");
|
||||
WriteLine($"{i}! throws {ex.GetType()}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ decimal taxToPay = CalculateTax(amount: 149, twoLetterRegionCode: "FR");
|
|||
WriteLine($"You must pay {taxToPay} in tax.");
|
||||
*/
|
||||
|
||||
RunCardinalToOrdinal();
|
||||
//RunCardinalToOrdinal();
|
||||
|
||||
//RunFactorial();
|
||||
RunFactorial();
|
||||
|
||||
//RunFibImperative();
|
||||
|
||||
|
|
|
|||
|
|
@ -158,8 +158,19 @@ WriteLine(sam.Age);
|
|||
|
||||
sam.FavoriteIceCream = "Chocolate Fudge";
|
||||
WriteLine($"Sam's favorite ice-cream flavor is {sam.FavoriteIceCream}.");
|
||||
sam.FavoritePrimaryColor = "Red";
|
||||
WriteLine($"Sam's favorite primary color is {sam.FavoritePrimaryColor}.");
|
||||
|
||||
string color = "Black";
|
||||
|
||||
try
|
||||
{
|
||||
sam.FavoritePrimaryColor = color;
|
||||
WriteLine($"Sam's favorite primary color is {sam.FavoritePrimaryColor}.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLine("Tried to set {0} to '{1}': {2}",
|
||||
nameof(sam.FavoritePrimaryColor), color, ex.Message);
|
||||
}
|
||||
|
||||
/*
|
||||
Book book = new()
|
||||
|
|
@ -237,7 +248,16 @@ for (int i = 0; i < lamech.Children.Count; i++)
|
|||
|
||||
// Implementing functionality using local functions
|
||||
|
||||
WriteLine($"5! is {Person.Factorial(5)}");
|
||||
int number = -1; // change to -1 to make the exception handling code execute
|
||||
|
||||
try
|
||||
{
|
||||
WriteLine($"{number}! is {Person.Factorial(number)}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLine($"{ex.GetType()} says: {ex.Message} number was {number}.");
|
||||
}
|
||||
|
||||
// Pattern matching with objects
|
||||
|
||||
|
|
|
|||
|
|
@ -3,14 +3,16 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.2.32210.308
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssembliesAndNamespaces", "AssembliesAndNamespaces\AssembliesAndNamespaces.csproj", "{4FD636C5-91F6-46AC-97B7-2396F11A31A8}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssembliesAndNamespaces", "AssembliesAndNamespaces\AssembliesAndNamespaces.csproj", "{4FD636C5-91F6-46AC-97B7-2396F11A31A8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedLibrary", "SharedLibrary\SharedLibrary.csproj", "{EDEB4531-EE20-440B-BB41-84CDA5715BA7}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharedLibrary", "SharedLibrary\SharedLibrary.csproj", "{EDEB4531-EE20-440B-BB41-84CDA5715BA7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetEverywhere", "DotNetEverywhere\DotNetEverywhere.csproj", "{7509E104-A3AE-4AEB-9656-D83A15D5CD70}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetEverywhere", "DotNetEverywhere\DotNetEverywhere.csproj", "{7509E104-A3AE-4AEB-9656-D83A15D5CD70}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ControlSDK", "ControlSDK\ControlSDK.csproj", "{76808C33-E138-4170-9621-122C1993B36E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceLinks", "SourceLinks\SourceLinks.csproj", "{FA7C1721-0B08-42CA-A075-66FFEF57B9A5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -33,6 +35,10 @@ Global
|
|||
{76808C33-E138-4170-9621-122C1993B36E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{76808C33-E138-4170-9621-122C1993B36E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{76808C33-E138-4170-9621-122C1993B36E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FA7C1721-0B08-42CA-A075-66FFEF57B9A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FA7C1721-0B08-42CA-A075-66FFEF57B9A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FA7C1721-0B08-42CA-A075-66FFEF57B9A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FA7C1721-0B08-42CA-A075-66FFEF57B9A5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
|||
3
vs4win/Chapter07/SourceLinks/Program.cs
Normal file
3
vs4win/Chapter07/SourceLinks/Program.cs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
string name = "Timothée Chalamet";
|
||||
int length = name.Count();
|
||||
Console.WriteLine($"{name} has {length} characters.");
|
||||
10
vs4win/Chapter07/SourceLinks/SourceLinks.csproj
Normal file
10
vs4win/Chapter07/SourceLinks/SourceLinks.csproj
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -67,7 +67,7 @@
|
|||
case 11: // special cases for 11th to 13th
|
||||
case 12:
|
||||
case 13:
|
||||
return $"{number}th";
|
||||
return $"{number:N0}th";
|
||||
default:
|
||||
int lastDigit = number % 10;
|
||||
|
||||
|
|
@ -79,13 +79,13 @@
|
|||
_ => "th"
|
||||
};
|
||||
|
||||
return $"{number}{suffix}";
|
||||
return $"{number:N0}{suffix}";
|
||||
}
|
||||
}
|
||||
|
||||
static void RunCardinalToOrdinal()
|
||||
{
|
||||
for (int number = 1; number <= 1030; number++)
|
||||
for (int number = 1; number <= 1500; number++)
|
||||
{
|
||||
Write($"{CardinalToOrdinal(number)} ");
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@
|
|||
|
||||
static void RunFactorial()
|
||||
{
|
||||
for (int i = -2; i <= 14; i++)
|
||||
for (int i = -2; i <= 15; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -127,7 +127,7 @@
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLine($"{ex.GetType()}: {ex.Message}.");
|
||||
WriteLine($"{i}! throws {ex.GetType()}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ decimal taxToPay = CalculateTax(amount: 149, twoLetterRegionCode: "FR");
|
|||
WriteLine($"You must pay {taxToPay} in tax.");
|
||||
*/
|
||||
|
||||
RunCardinalToOrdinal();
|
||||
//RunCardinalToOrdinal();
|
||||
|
||||
//RunFactorial();
|
||||
RunFactorial();
|
||||
|
||||
//RunFibImperative();
|
||||
|
||||
|
|
|
|||
|
|
@ -158,8 +158,19 @@ WriteLine(sam.Age);
|
|||
|
||||
sam.FavoriteIceCream = "Chocolate Fudge";
|
||||
WriteLine($"Sam's favorite ice-cream flavor is {sam.FavoriteIceCream}.");
|
||||
sam.FavoritePrimaryColor = "Red";
|
||||
WriteLine($"Sam's favorite primary color is {sam.FavoritePrimaryColor}.");
|
||||
|
||||
string color = "Black";
|
||||
|
||||
try
|
||||
{
|
||||
sam.FavoritePrimaryColor = color;
|
||||
WriteLine($"Sam's favorite primary color is {sam.FavoritePrimaryColor}.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLine("Tried to set {0} to '{1}': {2}",
|
||||
nameof(sam.FavoritePrimaryColor), color, ex.Message);
|
||||
}
|
||||
|
||||
/*
|
||||
Book book = new()
|
||||
|
|
@ -237,7 +248,16 @@ for (int i = 0; i < lamech.Children.Count; i++)
|
|||
|
||||
// Implementing functionality using local functions
|
||||
|
||||
WriteLine($"5! is {Person.Factorial(5)}");
|
||||
int number = -1; // change to -1 to make the exception handling code execute
|
||||
|
||||
try
|
||||
{
|
||||
WriteLine($"{number}! is {Person.Factorial(number)}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLine($"{ex.GetType()} says: {ex.Message} number was {number}.");
|
||||
}
|
||||
|
||||
// Pattern matching with objects
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
},
|
||||
{
|
||||
"path": "DotNetEverywhere"
|
||||
},
|
||||
{
|
||||
"path": "SourceLinks"
|
||||
}
|
||||
]
|
||||
}
|
||||
3
vscode/Chapter07/SourceLinks/Program.cs
Normal file
3
vscode/Chapter07/SourceLinks/Program.cs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
string name = "Timothée Chalamet";
|
||||
int length = name.Count();
|
||||
Console.WriteLine($"{name} has {length} characters.");
|
||||
10
vscode/Chapter07/SourceLinks/SourceLinks.csproj
Normal file
10
vscode/Chapter07/SourceLinks/SourceLinks.csproj
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in a new issue