This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Programs | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
UserLogIn(true, true, true); | |
} | |
private static void UserLogIn(bool hasUsername, bool hasPassword, bool isAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 = | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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:"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
internal class SampleCode | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
NewerOlder