Skip to content

Instantly share code, notes, and snippets.

View emmanuel-pangan's full-sized avatar

Emmanuel Pangan emmanuel-pangan

View GitHub Profile
@emmanuel-pangan
emmanuel-pangan / Program.cs
Created January 23, 2024 10:12
How to Avoid Multiple Nested If-Else Statements Using Guard Clause
namespace Programs
{
internal class Program
{
static void Main(string[] args)
{
UserLogIn(true, true, true);
}
private static void UserLogIn(bool hasUsername, bool hasPassword, bool isAdmin)
@emmanuel-pangan
emmanuel-pangan / Program.cs
Created December 14, 2023 08:48
How to Create Classes - How to C# for Beginners (Tutorial 09)
class Program
{
static void Main(string[] args)
{
// Class is a blueprint for creating objects.
// Objects are instances of a class that can hold fields and methods.
Cat cat1 = new Cat();
cat1.name = "Garfield";
cat1.Eat("lasagna");
@emmanuel-pangan
emmanuel-pangan / Program.cs
Last active November 19, 2023 04:13
How to Create Methods - How to C# for Beginners (Tutorial 08)
class Program
{
static void Main(string[] args)
{
// A method is a block of code that we can use many times we want.
Display("Mom");
Display("Dad");
int squareOf2 = SquareOfNumber(2);
int squareOf3 = SquareOfNumber(3);
@emmanuel-pangan
emmanuel-pangan / Program.cs
Created November 4, 2023 03:31
How to Use For Loop - How to C# for Beginners (Tutorial 07)
// For loop is a fancier while loop with initialization and iterator.
string[] fruits = { "Apple", "Orange", "Banana" };
for (int i = 0; i < fruits.Length; i++)
{
Console.WriteLine(fruits[i]);
}
string[][] foods =
{
@emmanuel-pangan
emmanuel-pangan / Program.cs
Created October 25, 2023 02:59
How to Use While Loop - How to C# for Beginners (Tutorial 06)
// While loop repeats the code while its condition is TRUE.
double tuitionFee = 5000;
while (tuitionFee > 0)
{
Console.WriteLine($"Tuition Fee:\n{tuitionFee}");
Console.WriteLine("Please enter your new payment:");
double payment = double.Parse(Console.ReadLine());
// If payment is zero or negative.
@emmanuel-pangan
emmanuel-pangan / Program.cs
Created October 17, 2023 02:23
How to Make an Array - How to C# for Beginners (Tutorial 05)
// Variables like this becomes messy.
string student1 = "John";
string student2 = "Michael";
string student3 = "Petra";
// To solve this, you can make an array.
string[] students = { "John", "Michael", "Petra" };
Console.WriteLine("Student Name: " + students[students.Length - 1]);
@emmanuel-pangan
emmanuel-pangan / Program.cs
Last active October 10, 2023 08:51
How to Use If, Else if, and Else Statements – How to C# for Beginners (Tutorial 04)
// IF-ELSE STATEMENTS
Console.WriteLine("What's your age?");
int age = int.Parse(Console.ReadLine());
// If statement allow us to add decisions to our codes.
bool isAgeGreaterThan18 = age > 18;
if (isAgeGreaterThan18)
{
Console.WriteLine("You're an adult.");
Console.WriteLine("Please enter your salary:");
@emmanuel-pangan
emmanuel-pangan / SampleCode.cs
Last active October 23, 2023 12:32
What are the Basics of Comments in C# (Shortcuts)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
internal class SampleCode
{
@emmanuel-pangan
emmanuel-pangan / Program.cs
Last active October 23, 2023 12:31
What are the Basics of Comments in C# (Single-line and Multi-line)
// Single-line Comment
Console.WriteLine("Above");
// Whatever you want.
Console.WriteLine("Below");
// Calculates the next leap year.
var nextLeapYear = DateTime.Now.AddYears(4); // Description here.
// TODO: 1. Optimize this code. 2. Google or go to StackOverflow. 3. Copy-paste the code. 4. Refactor again.
@emmanuel-pangan
emmanuel-pangan / Program.cs
Last active September 28, 2023 12:07
How to Declare Variables and Data Types - How to C# for Beginners (Tutorial 03)
// STRING
string name = "John";
string concatenate = "1" + "1"; // The variable "total" is renamed to "concatenate".
Console.WriteLine(concatenate);
// CHAR
char character = 'A';
Console.WriteLine(character);
// INT