using System.Collections.Generic;
using Microsoft.Data.SqlClient;
public static void Main()
Console.WriteLine("Hello World");
Hawk myHawk = new Hawk();
Rabbit myRabbit = new Rabbit();
Fish myFish = new Fish();
public static SqlConnection ConnectToDatabase()
string ConnectionString = "Server=SQLEXPRESS;Catalog=CompanyDatabase;User Id=sa;Password=2BeChanged!;";
SqlConnection conn = new SqlConnection(ConnectionString);
catch (SqlException ex) when (ex.Number == 1)
Console.WriteLine($"We hit the SqlException catch block #1 - message = {ex.Message}");
catch (SqlException ex) when (ex.Number == 2)
Console.WriteLine($"We hit the SqlException catch block #2 - message = {ex.Message}");
Console.WriteLine("We hit the finally code block. This block always executes.");
public static SqlDataReader QueryDatabaseReturnReader(SqlConnection conn, string queryString)
SqlDataReader reader = null;
SqlCommand Cmd = new SqlCommand(queryString,conn);
reader = Cmd.ExecuteReader();
catch (SqlException ex) when (ex.Number == 1)
Console.WriteLine("We hit the 1st catch block with error message = {ex.Message}");
catch (SqlException ex) when (ex.Number == 2)
Console.WriteLine($"We hit the SqlException catch block #2 - message = {ex.Message}");
Console.WriteLine("We hit the finally block. This block always executes.");
public static void DoStuff()
string queryString = "SELECT FirstName FROM Customer;";
Console.WriteLine("The query string is empty");
Console.WriteLine($"The value of counter in the do/while loop is: {counter}");
Console.WriteLine($"The value of counter in the While loop is: {counter}");
var planoNames= new List<string> {"Roger","Tracy","Brandon"};
planoNames.Add("Esther");
planoNames.Add("Rascal");
List<string> missouriNames = new List<string>();
missouriNames.Add("Bryson");
missouriNames.Add("Kristen");
missouriNames.Add("Finn");
missouriNames.Add("Obi");
missouriNames.Add("Penny");
missouriNames.Add("Bella");
missouriNames.Add("Milo");
missouriNames.Add("Rue");
List<int> numbers = new List<int>();
var names = new string[] {"Scott", "Ana", "Felipe" };
names = [..names,"Roger"];
var moreNumbers = new List<int> {8,5,3,4,2,6,7,1,9};
foreach (string name in planoNames)
Console.WriteLine($"The value of name is: {name.ToUpper()}");
foreach (string name in missouriNames)
Console.WriteLine($"The value of name is: {name.ToUpper()}");
foreach (int number in numbers)
Console.WriteLine($"The value of number is: {number}");
Console.WriteLine($"The element in the 2nd element in planoNames collection is: {planoNames[1]}");
Console.WriteLine($"The next to last element in the planoNames collection is: {planoNames[^2]}");
foreach (var name in planoNames[2..5])
Console.WriteLine($"Hello {name.ToUpper()}");
foreach (var name in planoNames)
Console.WriteLine($"Sorted! {name.ToUpper()}");
foreach (var number in moreNumbers)
Console.WriteLine($"{number}");
Console.WriteLine($"I found 7 at index {moreNumbers.IndexOf(7)}");
foreach (var number in moreNumbers)
Console.WriteLine($"{number}");
List<int> scores = [97, 98, 81, 60, 50];
Console.WriteLine("LINQ query output");
IEnumerable<int> scoreQuery =
foreach (int i in scoreQuery)
Console.WriteLine(i + " ");
List<int> scores2 = [3,45,82,97,92,100,81,60,50,40];
Console.WriteLine("LINQ query output for scores2 list");
IEnumerable<int> scoreQuery2 =
foreach (int i in scoreQuery2)
Console.WriteLine(i + " ");
string GetWeatherDisplay(double tempInCelsius) => tempInCelsius < 20.0 ? "Cold." : "Perfect!";
Console.WriteLine(GetWeatherDisplay(15));
Console.WriteLine(GetWeatherDisplay(34));
IEnumerable<string> scoreQuery3 =
select $"The score is {score}";
foreach (string i in scoreQuery3)
Console.WriteLine("Hello OOP!");
var p1 = new Person("Roger", "Barnes", new DateOnly(1964,6,25));
var p2 = new Person("Tracy", "Barnes", new DateOnly(1965,8,30));
var p3 = new Person("Brandon", "Barnes", new DateOnly(1996,2,16));
List<Person> people = [p1,p2,p3];
Console.WriteLine(people.Count);
Console.WriteLine("Is my pet living? " + myPet.IsLiving.ToString());
Truck myTruck = new Truck();
myTruck.HasEightFootBed = true;
myTruck.HasReceiverHitch = true;
Console.WriteLine($"My dog makes the sound: {myDog.Sound}");
Console.WriteLine($"My cat makes the sound: {myCat.Sound}");
public class Person (string firstName, string lastName, DateOnly birthday)
public string First {get; } = firstName;
public string Last {get; } = lastName;
public DateOnly Birthday {get; } = birthday;
private bool _Exists = true;
private bool _IsLiving = true;
private bool _IsWarmBlooded = false;
private bool _HasMammaryGlands = false;
private bool _HasLungs = false;
private bool _Has3BonesInMiddleEar = false;
private bool _HasDiaphram = false;
private bool _HasFourLegs = false;
private bool _HasFourChamberedHeart = false;
public bool IsWarmBlooded
get {return _IsWarmBlooded; }
set {_IsWarmBlooded = value;}
public bool HasMammaryGlands
get {return _HasMammaryGlands; }
set {_HasMammaryGlands = value;}
public bool Has3BonesInMiddleEar
get {return Has3BonesInMiddleEar;}
set {_Has3BonesInMiddleEar = value;}
get {return _HasDiaphram;}
set {HasDiaphram = value;}
get {return _HasFourLegs;}
set {_HasFourLegs = value;}
public bool HasFourChamberedHeart
get {return _HasFourChamberedHeart;}
set {_HasFourChamberedHeart = value;}
Console.WriteLine(GeoLocateAnimal() ? "Pet Was Found!" : "Pet Was Not Found");
private bool GeoLocateAnimal()
public class Mammal : Animal
public bool HasHair {get; set;} = false;
public bool Hasfur {get; set;} = false;
public class Pet : Mammal
Console.WriteLine("We went for a walk");
private string _VehicleMake = "Dodge";
private bool _HasAnEngine = true;
private bool _HasWheels = true;
private bool _HasTires = true;
private bool _HasFrontBumper = true;
private bool _HasRearBumper = true;
private bool _HasRadio = true;
public string VehicleMake
get {return _VehicleMake; }
get {return _HasAnEngine; }
get {return _HasWheels; }
public bool HasFrontBumper
get {return _HasFrontBumper; }
public bool HasRearBumper
get {return _HasRearBumper; }
public virtual void Honk()
Console.WriteLine("Tooooooot!");
public class Truck : Vehicle
private bool _HasSixFootBed = false;
private bool _HasEightFootBed = false;
private bool _HasStepTailgate = false;
private bool _HasReceiverHitch = false;
private bool _HasSlidingGlassRearWindow = false;
public bool HasSixFootBed
get{return _HasSixFootBed; }
set{_HasSixFootBed = value; }
public bool HasEightFootBed
get{return _HasEightFootBed; }
set{_HasEightFootBed = value; }
public bool HasStepTailgate
get{return _HasStepTailgate; }
set{_HasStepTailgate = value; }
public bool HasReceiverHitch
get{return _HasReceiverHitch;}
set{_HasReceiverHitch = value;}
public bool HasSlidingGlassRearWindow
get{return _HasSlidingGlassRearWindow;}
set{_HasSlidingGlassRearWindow = value;}
Console.WriteLine("We are towing like Tow Mater!");
public override void Honk()
Console.WriteLine("Beep Beep!");
public abstract class Creature
public abstract string Sound { get; }
public virtual void Move()
Console.WriteLine("Moving...");
public class Cat : Creature
public override string Sound => "Meow";
public override void Move()
Console.WriteLine("Walking like a cat...");
public class Dog : Creature
public override string Sound => "Woof";
public override void Move()
Console.WriteLine("Running like a dog...");
Console.WriteLine("The rabbit runs away!");
Console.WriteLine("The hawk is searching for food!");
class Fish : IPredator, IPrey
Console.WriteLine("The fish hunts for food");
Console.WriteLine("The fish swims away");