// ---
// jupyter:
//   jupytext:
//     text_representation:
//       extension: .cs
//       format_name: light
//       format_version: '1.5'
//       jupytext_version: 1.14.4
//   kernelspec:
//     display_name: .NET (C#)
//     language: C#
//     name: .net-csharp
// ---

// # String

// +
//Print variables
string firstName = "Huy";
string lastName = "Nguyen";
Console.WriteLine($"My name is {firstName} {lastName}");
Console.WriteLine($"My name has {firstName.Length} letters");

//Trimming spaces
string hello = "       Hello World        ";
Console.WriteLine($"Trim start spaces {hello.TrimStart()}");
Console.WriteLine($"Trim end spaces {hello.TrimEnd()}");
Console.WriteLine($"Trim spaces {hello.Trim()}");

//Replace string
string hello2 = "   Hello Superman    ";
Console.WriteLine($"Replace Hello with Hi : {hello2.Replace("Hello", "Hi")}");

//Upper and Lower
string hello3 = "     Hello Babe    ";
Console.WriteLine($"Convert Hello Babe to HELLO BABE : {hello3.ToUpper()}");
Console.WriteLine($"Convert Hello Babe to hello babe : {hello3.ToLower()}");

//Search a string
string songLyrics = "You say goodbye, I say hello";
Console.WriteLine($"The Phrase : {songLyrics}");
Console.WriteLine($"- Contains goodBye : {songLyrics.Contains("goodBye")}");
Console.WriteLine($"- Contains goodbye : {songLyrics.Contains("goodbye")}");
Console.WriteLine($"- Starts with Yo : {songLyrics.StartsWith("Yo")}");
Console.WriteLine($"- Starts with goo : {songLyrics.StartsWith("goo")}");
Console.WriteLine($"- Ends with lo : {songLyrics.EndsWith("lo")}");

// -

// # Number

// +
//First Grade Math
int a = 18;
int b = 61;
int c = a + b;
Console.WriteLine($"a + b = {a} + {b} = {c}");
Console.WriteLine($"a - b = {a} - {b} = {a-b}");
Console.WriteLine($"a * b = {a} * {b} = {a*b}");
Console.WriteLine($"a / b = {a} / {b} = {a/b}");
Console.WriteLine($"a / (double)b = {a} / {(double)b} = {a/(double)b}");
Console.WriteLine($"a % b = {a} % {b} = {a%b}");
Console.WriteLine($"6 % 2 = {6} % {2} = {6%2}");
Console.WriteLine($"6 % (double)2 = {6} % {(double)2} = {6%2}");

//Min and Max
short shortMax = short.MaxValue;
short shortMin = short.MinValue;
int intMax = int.MaxValue;
int intMin = int.MinValue;
long longMax = long.MaxValue;
long longMin = long.MinValue;
double doubMax = double.MaxValue;
double doubMin = double.MinValue;
decimal decMax = decimal.MaxValue;
decimal decMin = decimal.MinValue;
Console.WriteLine($"Max short value : {shortMax}");
Console.WriteLine($"Min short value : {shortMin}");
Console.WriteLine($"Max int value : {intMax}");
Console.WriteLine($"Min int value : {intMin}");
Console.WriteLine($"Max long value : {longMax}");
Console.WriteLine($"Min long value : {longMin}");
Console.WriteLine($"Overflow max int value : {intMax + 1}");
Console.WriteLine($"Overflow min int value : {intMax - 1}");
Console.WriteLine($"Max double value : {doubMax}");
Console.WriteLine($"Min double value : {doubMin}");
Console.WriteLine($"Max decimal value : {decMax}");
Console.WriteLine($"Min decmial value: {decMin}");

//Decimal Suffix M
decimal suffixDecimal = 3.0M;
Console.WriteLine(@$"To assign a value to a decimal varible,
                    we need suffix M : Decimal value 3.0M for {suffixDecimal}");
decimal adec = (decimal)2;
Console.WriteLine(@$"To assign a non-decimal value to a decimal varible,
                    we need cast it to decimal with (demimal)number :
                    Decimal value (decimal)2 for {adec}");
Console.WriteLine($"Use GetType() to get type of variable 'adec' : {adec.GetType()}");

//Area of a circle
double radius = 2;
double area = Math.PI * radius * radius;
Console.WriteLine($"Area = Pi*R^2 = {area} with R = {radius}");
// -

// # Array, List, and Collection

//notice 'var' keyword 
var names = new List<string> {"Ai", "Huy"};
names.Add("Hello");
names.Remove("Hello");
foreach (string name in names){
    Console.WriteLine(name.ToUpper());
}

// # Search, Sort, Index Lists

//notice 'var' keyword 
var names = new List<string> {"Hello","Ai", "Huy"};
names.Add("Hello");
names.Remove("Hello");
names.Prepend("Hi");
foreach (string name in names){
    Console.WriteLine(name.ToUpper());
}
var index = names.IndexOf("huy");
var index2 = names.IndexOf("Huy");
Console.WriteLine(index);
Console.WriteLine(index2);
names.Sort();
Console.WriteLine("After sorting ...");
foreach (string name in names){
    Console.WriteLine(name.ToUpper());
}
for(int i=0; i < names.Count; i++){
    Console.WriteLine($"--> {names[i]}");
}


// # Object Oriented Programming





StarcoderdataJupyterScriptsDedupFiltered