mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-07 15:23:54 +00:00
Initial commit
This commit is contained in:
parent
7fa1000b05
commit
143e708681
12 changed files with 98 additions and 23 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue