Learning Path Details
Foundation in C#: Object Oriented Programming Part 1 from Tim Corey
Description:
Module 4 of the Complete Foundation in C# Course Series, the focus is on classes and objects, including static and instantiated classes, properties, and namespaces. The last section includes the introduction of Class Libraries and a mini-project.
Key Takeaways:
This is an introduction to the concepts behind object-oriented programming (OOP). It covers static and instantiated classes, properties and methods, namespaces, and class libraries.
Technologies Learned:
- .NET;
- .NET Framework;
- .NET Framework 4.7.2;
- C#;
- Class Library;
- Classes;
- Console Application;
- Instatiated Classes;
- Namespaces;
- Object-Oriented Programming;
- Properties;
- Static Classes;
This learning resource was completed on 8/24/2021.
Find the Resource here:
Practice Projects
Mini Project
Description:
The homework from the Lesson 7, Mini-Project, of Module 4, Object-Oriented Programming, Part 1, of the Complete Foundation in C# Course Series from Tim Corey. We are to recreate the guest book project without looking back. Just take the concept and create the application.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Class Library;
- Console Application;
Find the Project here:
Code Snippet:
using System;
using System.Collections.Generic;
using GuestBookLibrary.Models;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
List<GuestModel> guestlist = new List<GuestModel>();
GetGuestInformation(guestlist);
PrintOutGuestList(guestlist);
_ = Console.ReadLine();
}
private static void PrintOutGuestList(List<GuestModel> guests)
{
foreach ( GuestModel guest in guests )
{
Console.WriteLine(guest.GuestMessage);
}
}
private static void GetGuestInformation(List<GuestModel> guests)
{
string moreguestcoming;
do
{
bool isagevalid;
GuestModel guest = new GuestModel
{
FirstName = GetInfoFromConsole("What is your first name: "),
LastName = GetInfoFromConsole("What is your last name: ")
};
do
{
string agetext = GetInfoFromConsole("How old are you: ");
isagevalid = int.TryParse(agetext, out int agenumber);
if ( !isagevalid )
{
Console.WriteLine("Please enter your age as a number.");
}
guest.Age = agenumber;
} while ( !isagevalid );
guest.Hometown = GetInfoFromConsole("What is your hometowm: ");
guest.MessageToHost = GetInfoFromConsole("What is your message for the host: ");
guests.Add(guest);
moreguestcoming = GetInfoFromConsole("Are more guest coming (yes/no): ");
Console.Clear();
} while ( moreguestcoming.ToLower() == "yes" );
}
private static string GetInfoFromConsole(string message)
{
string output;
Console.Write(message);
output = Console.ReadLine();
return output;
}
}
}
Class Libraries
Description:
The homework from the Lesson 6, Class Libraries, of Module 4, Object-Oriented Programming, Part 1, of the Complete Foundation in C# Course Series from Tim Corey. We are to create a Class Library that holds a Person Class. Use that Class in a Console Application.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Class Library;
- Console Application;
Find the Project here:
Code Snippet:
namespace DemoLibrary
{
public class PersonModel
{
public string FirstName
{
get; set;
}
public string LastName
{
get; set;
}
public string FullName
{
get
{
return $"{FirstName} {LastName}";
}
}
}
}
Namespaces
Description:
The homework from the Lesson 5, Namespaces, of Module 4, Object-Oriented Programming, Part 1, of the Complete Foundation in C# Course Series from Tim Corey. We are to create a Class file and change the Namespace to be something different. Call a method in that class.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
using System;
using ConsoleUI.Models;
using ConsoleUI.UserInteraction;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
PersonModel person = new PersonModel
{
FirstName = "Tim",
LastName = "Corey"
};
Messages.GreetPerson(person);
_ = Console.ReadLine();
}
}
}
Properties
Description:
The homework from the Lesson 4, Properties, of Module 4, Object-Oriented Programming, Part 1, of the Complete Foundation in C# Course Series from Tim Corey. We are to create a Class that has Properties for street address, city, state, and zip code. Then add a FullAddress property that is read-only.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
namespace ConsoleUI
{
internal class AddressModel
{
internal string StreetAddress
{
get; set;
}
internal string City
{
get; set;
}
internal string State
{
get; set;
}
internal string ZipCode
{
get; set;
}
internal string FullAddress
{
get
{
return $"{StreetAddress}, {City} {State} {ZipCode}";
}
}
internal AddressModel()
{
}
internal AddressModel(string streetAddress, string city, string state, string zipCode)
{
StreetAddress = streetAddress;
City = city;
State = state;
ZipCode = zipCode;
}
}
}
Instantiated Classes
Description:
The homework from the Lesson 3, Instantiated Classes, of Module 4, Object-Oriented Programming, Part 1, of the Complete Foundation in C# Course Series from Tim Corey. We are to create a Console Application that has a Person Class and an Address Class.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
namespace ConsoleUI
{
internal class PersonModel
{
internal string FirstName
{
get; set;
}
internal string LastName
{
get; set;
}
internal AddressModel Address
{
get; set;
}
}
internal class AddressModel
{
internal string StreetAddress
{
get; set;
}
internal string City
{
get; set;
}
internal string State
{
get; set;
}
internal string ZipCode
{
get; set;
}
}
}
Static Classes
Description:
The homework from the Lesson 2, Static Classes, of Module 4, Object-Oriented Programming, Part 1, of the Complete Foundation in C# Course Series from Tim Corey. We are to create a Console Application with a Static Class that handles calculaltions.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
namespace ConsoleUI
{
internal static class CalculateData
{
internal static double Operate(double x, double y, char opp)
{
double output = 0.0;
switch ( opp )
{
case '+':
output = Add(x, y);
break;
case '-':
output = Subtract(x, y);
break;
case '*':
output = Multiply(x, y);
break;
case '/':
output = Divide(x, y);
break;
default:
UserMessages.DisplayErrorMessage("That is not a valid operation.");
break;
}
return output;
}
private static double Add(double x, double y)
{
double output = x + y;
return output;
}
private static double Subtract(double x, double y)
{
double output = x - y;
return output;
}
private static double Multiply(double x, double y)
{
double output = x * y;
return output;
}
private static double Divide(double x, double y)
{
double output = 0.0;
if ( y != 0.0 )
{
output = x / y;
}
else
{
UserMessages.DisplayErrorMessage("We cannot divide by zero.");
}
return output;
}
}
}