Learning Path Details
Foundation in C#: Common Syntax from Tim Corey
Description:
Module 2 of the Complete Foundation in C# Course Series, the focus is on the basic syntax of C#, including variables, conditionals, type conversion, loops (do-while, for, and foreach), sets (arrays, lists, and dictionary), and methods. At the end of the section on variables and conditionals, and again at the end of the section on methods, we build a mini-project together to tie together what we have learned.
Key Takeaways:
We cover the primitive data types in C#: string, bool, int (regular 32-bit, short 16-bit, and long 64-bit, signed and unsigned), double (and float), decimal, and byte. We cover the use of if and else statements and the switch-case statement, including the comparison and join operators.
Tim demonstrates the basic syntax and use of do/while (and while) loops, for loops, foreach loops, and the creation and use of arrays, Lists, and Dictionaries. Finally, the concept of methods, which is central to object-oriented programming, is introduced.
Technologies Learned:
- .NET;
- .NET Framework;
- .NET Framework 4.5;
- .NET Framework 4.7;
- .NET Framework 4.7.2;
- arrays;
- booleans;
- C#;
- decimal floating point values;
- Dictionaries;
- do/while loops;
- double-precision floating point values;
- for loops;
- foreach loops;
- if/else;
- integer values;
- Lists;
- methods;
- string interpolation;
- strings;
- switch/case;
- type conversion;
- while loops;
This learning resource was completed on 8/5/2021.
Find the Resource here:
Practice Projects
Console Guest Book
Description:
The homework from the Lesson 13, Mini-Project, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to build a Console Guest Book. Ask the user for their name and how many are in their party. Keep track of how many people are at the party. At the end, print out the guest list and the total number of guests.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
https://github.com/Spartan-CSharp/CommonSyntax-ConsoleGuestBook
Code Snippet:
using System;
using System.Collections.Generic;
namespace ConsoleUI
{
internal class Program
{
private static void Main(string[] args)
{
//Start counting guests at 0
int totalguests = 0;
// Initialize guest list
List<string> guestlist = new List<string>();
// Initialize done checker
string done;
do
{
//Get user name
string guestname = GetGuestName();
//Add name to guest list
guestlist.Add(guestname);
//Get # of people in party
int partysize = GetPartySize();
//Add # of people to total guests
totalguests += partysize;
//Ask if done
Console.Write("Done (yes/no): ");
done = Console.ReadLine();
//If not done loop back to get user name
//If done move on
} while ( done.ToLower() != "yes" );
//Print out list of people
//Print out total # of people
DisplayGuestList(guestlist, totalguests);
_ = Console.ReadLine();
}
private static string GetGuestName()
{
Console.Write("What is the name of your party: ");
string output = Console.ReadLine();
return output;
}
private static int GetPartySize()
{
bool issizevalid;
int output;
do
{
Console.Write("How many people in your party: ");
string partysize = Console.ReadLine();
issizevalid = int.TryParse(partysize, out output);
if ( !issizevalid )
{
Console.WriteLine("Please enter the number using digits.");
}
} while ( !issizevalid );
return output;
}
private static void DisplayGuestList(List<string> guestList, int totalGuests)
{
Console.WriteLine("Party Guest List");
foreach ( string guest in guestList )
{
Console.WriteLine(guest);
}
Console.WriteLine($"Total Guests: {totalGuests}");
}
}
}
Methods
Description:
The homework from the Lesson 12, Methods, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to create a welcome method, a method to ask for the user's name, and another to tell that user "Hello __".
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
using System;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
WelcomeUser();
string name = GetUserName();
SayHello(name);
_ = Console.ReadLine();
}
private static void WelcomeUser()
{
Console.WriteLine("Welcome to Foundation in C#!");
}
private static string GetUserName()
{
Console.Write("What is your first name: ");
string output = Console.ReadLine();
return output;
}
private static void SayHello(string firstName)
{
Console.WriteLine($"Hello {firstName}!");
}
}
}
Loops: foreach
Description:
The homework from the Lesson 11, Loops: foreach, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to ask the user for their first name. Continue asking for first names until there are no more. Then loop through each name using foreach and tell them hello.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
using System;
using System.Collections.Generic;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
List<string> firstnames = new List<string>();
string morenames;
do
{
Console.Write("Enter a first name: ");
firstnames.Add(Console.ReadLine());
Console.Write("Any more (yes/no)? ");
morenames = Console.ReadLine();
} while ( morenames.ToLower() != "no" );
foreach ( string firstname in firstnames )
{
Console.WriteLine($"Hello {firstname}!");
}
_ = Console.ReadLine();
}
}
}
Loops: for
Description:
The homework from the Lesson 10, Loops: for, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to ask the user for a comma-separated list of first names (no spaces). Split the string into a string array. Loop through the array and tell each person hello.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
using System;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
Console.Write("Enter a comma-separated list of first names (no spaces): ");
string firstnamelist = Console.ReadLine();
string[] firstnames = firstnamelist.Split(',');
for ( int i = 0; i < firstnames.Length; i++ )
{
Console.WriteLine($"Hello {firstnames[i]}!");
}
_ = Console.ReadLine();
}
}
}
Sets: Dictionary
Description:
The homework from the Lesson 9, Sets: Dictionary, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to create a Dictionary list of employee IDs and the name that goes with that ID. Fill it with a few records. Then ask the user for their ID and return their name.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
https://github.com/Spartan-CSharp/CommonSyntax-SetsDictionary
Code Snippet:
using System;
using System.Collections.Generic;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
Dictionary<int, string> employees = new Dictionary<int, string>
{
[1] = "Tim",
[2] = "Sue",
[3] = "Bob"
};
Console.Write("Enter your Employee ID: ");
string employeeidtext = Console.ReadLine();
bool isidvalid = int.TryParse(employeeidtext, out int employeeid);
if ( isidvalid && employeeid > 0 && employeeid < 4 )
{
Console.WriteLine($"Welcome {employees[employeeid]}!");
}
else
{
Console.WriteLine("That is not a valid ID.");
}
_ = Console.ReadLine();
}
}
}
Sets: Lists
Description:
The homework from the Lesson 8, Sets: Lists, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to add students to a class roster until there are no more students. Then print out the count of the students to the Console.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
using System;
using System.Collections.Generic;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
List<string> studentnames = new List<string>();
int studentcount = 0;
string morestudents;
do
{
Console.Write("Enter Student Name: ");
studentnames.Add(Console.ReadLine());
studentcount++;
Console.Write("More Students (yes/no): ");
morestudents = Console.ReadLine();
} while ( morestudents == "yes" );
Console.WriteLine($"You entered {studentcount} students.");
_ = Console.ReadLine();
}
}
}
Sets: Arrays
Description:
The homework from the Lesson 7, Sets: Arrays, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to create an array of 3 names. Ask the user which number to select. When the user gives you a number, return that name.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
using System;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
string[] names = new string[] { "Tim", "Sue", "Bob" };
Console.Write("Pick a number from 1 to 3: ");
string numbertext = Console.ReadLine();
bool isvalidnumber = int.TryParse(numbertext, out int number);
if ( !isvalidnumber || number < 1 || number > 3 )
{
Console.WriteLine("That is not a valid number.");
_ = Console.ReadLine();
return;
}
Console.WriteLine($"The name in position {number} is {names[number - 1]}.");
_ = Console.ReadLine();
}
}
}
Do/While
Description:
The homework from the Lesson 6, Do/While, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to ask for the user's name. If their name is Tim, say "Hello Professor". Otherwise, say "Hi __". Do this until they type "exit".
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
using System;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
string name;
do
{
Console.Write("What is your name: ");
name = Console.ReadLine();
if ( name.ToLower() == "tim" )
{
Console.WriteLine("Hello Professor");
}
else if ( name.ToLower() != "exit" )
{
Console.WriteLine($"Hi {name}");
}
} while ( name.ToLower() != "exit" );
}
}
}
Mini-Project
Description:
The homework from the Lesson 5, Mini-Project, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to plan and build a Console Application that asks a user for their name and their age. If their name is Bob or Sue, address them as professor. If the person is under 21, recommend they wait X years to start this class.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
using System;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
Console.Write("What is your first name: ");
string firstname = Console.ReadLine();
Console.Write("How old are you: ");
string agetext = Console.ReadLine();
bool isagevalid = int.TryParse(agetext, out int age);
if ( firstname.ToLower() == "bob" || firstname.ToLower() == "sue" )
{
Console.WriteLine($"Hello Professor {firstname}");
}
else
{
Console.WriteLine($"Hello {firstname}");
}
if ( isagevalid )
{
if ( age < 21 )
{
int yearstowait = 21 - age;
Console.WriteLine($"I recommend you wait {yearstowait} years before starting this class");
}
}
else
{
Console.WriteLine("You must enter your age in digits");
}
_ = Console.ReadLine();
}
}
}
Type Conversion
Description:
The homework from the Lesson 4, Type Conversion, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to capture a user's age from the Console and then identify how old they were in the year 2000. If they were not born yet, tell them that instead.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
https://github.com/Spartan-CSharp/CommonSyntax-TypeConversion
Code Snippet:
using System;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
Console.Write("How old are you: ");
string agetext = Console.ReadLine();
bool isagevalid = int.TryParse(agetext, out int age);
if ( isagevalid )
{
age -= 21;
if ( age < 0 )
{
Console.WriteLine("You were not born yet in the year 2000!");
}
else
{
Console.WriteLine($"You were {age} years old in the year 2000.");
}
}
else
{
Console.WriteLine("Please enter your age using digits.");
}
_ = Console.ReadLine();
}
}
}
Conditionals
Description:
The homework from the Lesson 3, Conditionals, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to create a Console Application that asks the user for their name. Welcome Tim as professor or anyone else as a student.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
Code Snippet:
using System;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
Console.Write("What is your first name: ");
string firstname = Console.ReadLine();
if ( firstname.ToLower() == "tim" )
{
Console.WriteLine("Hello Professor!");
}
else
{
Console.WriteLine("Hello Student!");
}
_ = Console.ReadLine();
}
}
}
Basic Variables
Description:
The homework from the Lesson 2, Basic Variables, of Module 2, Common Syntax, of the Complete Foundation in C# Course Series from Tim Corey. We are to create a Console Application that has variables to hold a person's name, age, if they are alive, and their phone number.
Technologies Used:
- .NET;
- .NET Framework;
- .NET Framework 4.8;
- C#;
- Console Application;
Find the Project here:
https://github.com/Spartan-CSharp/CommonSyntax-BasicVariables
Code Snippet:
using System;
namespace ConsoleUI
{
internal class Program
{
private static void Main()
{
string firstname = "Pierre";
string lastname = "Plourde";
string fullname = $"{firstname} {lastname}";
int age = 47;
bool isalive = true;
string phonenumber = "905-439-7645";
Console.WriteLine($"Hi, {fullname}, you are {age} years old, your phone number is {phonenumber}, and you are alive? {isalive}.");
_ = Console.ReadLine();
}
}
}