diff --git a/FormulatrixBootcamp.sln b/FormulatrixBootcamp.sln index 55d678d..50eadd7 100644 --- a/FormulatrixBootcamp.sln +++ b/FormulatrixBootcamp.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 @@ -107,6 +107,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MyPractice", "MyPractice", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Youtube", "MyPractice\Youtube\Youtube.csproj", "{1EC38B64-67FE-4276-B62E-2714BC280EE5}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "W3 D2", "W3 D2", "{24A9828C-37FB-41FF-AD85-C74FD61DFF50}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Array", "W3 D2\Array\Array.csproj", "{C812F926-1AC2-4C07-B3C7-16E2BA57E5CC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArrayList", "W3 D2\ArrayList\ArrayList.csproj", "{E8E9CC1D-539D-4849-8B29-09FFC9308392}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HashSet", "W3 D2\HashSet\HashSet.csproj", "{AC39434B-0FCF-4A5F-A86C-8892670D1AC8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinkedList", "W3 D2\LinkedList\LinkedList.csproj", "{2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "List", "W3 D2\List\List.csproj", "{5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -281,11 +293,32 @@ Global {1EC38B64-67FE-4276-B62E-2714BC280EE5}.Debug|Any CPU.Build.0 = Debug|Any CPU {1EC38B64-67FE-4276-B62E-2714BC280EE5}.Release|Any CPU.ActiveCfg = Release|Any CPU {1EC38B64-67FE-4276-B62E-2714BC280EE5}.Release|Any CPU.Build.0 = Release|Any CPU + {C812F926-1AC2-4C07-B3C7-16E2BA57E5CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C812F926-1AC2-4C07-B3C7-16E2BA57E5CC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C812F926-1AC2-4C07-B3C7-16E2BA57E5CC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C812F926-1AC2-4C07-B3C7-16E2BA57E5CC}.Release|Any CPU.Build.0 = Release|Any CPU + {E8E9CC1D-539D-4849-8B29-09FFC9308392}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E8E9CC1D-539D-4849-8B29-09FFC9308392}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E8E9CC1D-539D-4849-8B29-09FFC9308392}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E8E9CC1D-539D-4849-8B29-09FFC9308392}.Release|Any CPU.Build.0 = Release|Any CPU + {AC39434B-0FCF-4A5F-A86C-8892670D1AC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC39434B-0FCF-4A5F-A86C-8892670D1AC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC39434B-0FCF-4A5F-A86C-8892670D1AC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC39434B-0FCF-4A5F-A86C-8892670D1AC8}.Release|Any CPU.Build.0 = Release|Any CPU + {2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3}.Release|Any CPU.Build.0 = Release|Any CPU + {5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution + {A718291C-B218-4283-837F-43CF360568AC} = {A718291C-B218-4283-837F-43CF360568AC} {77D0C1C7-A06B-4E05-9458-873709BD4BFD} = {44C682DF-E1C9-4394-813D-0CB989CD9262} {AA5CB577-831E-40F5-AABD-AFF7C56F8A57} = {44C682DF-E1C9-4394-813D-0CB989CD9262} {1A0A5FD8-8FC2-4ECA-8EB0-BAC6DF70E7BF} = {0458C07F-2B31-4DB7-97E4-315800A0B2C0} @@ -328,5 +361,10 @@ Global {3B5564AD-79B1-457F-B755-9FA9DEDB3A4D} = {FDC6C9B3-986B-4EB0-84D7-96609709D9FC} {B0E44C63-88D6-4812-B0C7-DC0185BA98F5} = {FDC6C9B3-986B-4EB0-84D7-96609709D9FC} {1EC38B64-67FE-4276-B62E-2714BC280EE5} = {B7BF6991-6661-4DAF-BC8F-7E0A82F7E090} + {C812F926-1AC2-4C07-B3C7-16E2BA57E5CC} = {24A9828C-37FB-41FF-AD85-C74FD61DFF50} + {E8E9CC1D-539D-4849-8B29-09FFC9308392} = {24A9828C-37FB-41FF-AD85-C74FD61DFF50} + {AC39434B-0FCF-4A5F-A86C-8892670D1AC8} = {24A9828C-37FB-41FF-AD85-C74FD61DFF50} + {2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3} = {24A9828C-37FB-41FF-AD85-C74FD61DFF50} + {5F05DFBC-6EF9-4F4F-8B6D-4E1490171568} = {24A9828C-37FB-41FF-AD85-C74FD61DFF50} EndGlobalSection EndGlobal diff --git a/W3 D2/Array/Array.csproj b/W3 D2/Array/Array.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/W3 D2/Array/Array.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/W3 D2/Array/Program.cs b/W3 D2/Array/Program.cs new file mode 100644 index 0000000..c81d078 --- /dev/null +++ b/W3 D2/Array/Program.cs @@ -0,0 +1,32 @@ +public class Program +{ + static void Main() + { + // two ways to create Array + int[] numbers1 = {1, 2, 3, 4, 5}; + int[] numbers2 = new int[5]; + numbers2[0] = 1; + numbers2[1] = 2; + numbers2[2] = 3; + numbers2[3] = 4; + numbers2[4] = 5; + + // resize array + Array.Resize(ref numbers1, 10); + Console.WriteLine(numbers1.Length); + + // reverse array + Array.Reverse(numbers2); // 5 4 3 2 1 + foreach (var number in numbers2) + { + Console.WriteLine(number); + } + + // sort array -> ascending + Array.Sort(numbers2); + foreach (var number in numbers2) + { + Console.WriteLine(number); + } + } +} \ No newline at end of file diff --git a/W3 D2/ArrayList/ArrayList.csproj b/W3 D2/ArrayList/ArrayList.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/W3 D2/ArrayList/ArrayList.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/W3 D2/ArrayList/Program.cs b/W3 D2/ArrayList/Program.cs new file mode 100644 index 0000000..83d1cd3 --- /dev/null +++ b/W3 D2/ArrayList/Program.cs @@ -0,0 +1,16 @@ +using System.Collections; + +public class Program +{ + static void Main() + { + // ArrayList is not safety + ArrayList list = new ArrayList() { + 1, "2", true, 3.4, 123.1f, 111M, new int[] {1, 2, 3} + }; + + // must unbox to access element of ArrayList + int intValue = (int) list[0]; + Console.WriteLine(intValue); + } +} \ No newline at end of file diff --git a/W3 D2/HashSet/HashSet.csproj b/W3 D2/HashSet/HashSet.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/W3 D2/HashSet/HashSet.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/W3 D2/HashSet/Program.cs b/W3 D2/HashSet/Program.cs new file mode 100644 index 0000000..bc9133e --- /dev/null +++ b/W3 D2/HashSet/Program.cs @@ -0,0 +1,43 @@ +public class Program +{ + static void Main() + { + // HashSet is type safety + // HashSet elements must be unique + HashSet hs1 = new(); + hs1.Add(1); + hs1.Add(2); + hs1.Add(2); // this will be discarded + hs1.Add(3); + hs1.Add(4); + PrintHashSet(hs1, nameof(hs1)); + + HashSet hs2 = new HashSet() {3, 4, 5, 6}; + PrintHashSet(hs2, nameof(hs2)); + + HashSet except = new HashSet(hs1); + except.ExceptWith(hs2); + PrintHashSet(except, nameof(except)); + + HashSet union = new HashSet(hs1); + union.UnionWith(hs2); + PrintHashSet(union, nameof(union)); + + HashSet intersect = new HashSet(hs1); + intersect.IntersectWith(hs2); + PrintHashSet(intersect, nameof(intersect)); + + Console.WriteLine($"except is subset of union: {except.IsSubsetOf(union)}"); + Console.WriteLine($"union is superset of except: {union.IsSupersetOf(except)}"); + } + + static void PrintHashSet(HashSet hashSet, string varName) + { + Console.Write(varName + ": "); + foreach (var hs in hashSet) + { + Console.Write($"{hs} "); + } + Console.WriteLine(); + } +} \ No newline at end of file diff --git a/W3 D2/LinkedList/LinkedList.csproj b/W3 D2/LinkedList/LinkedList.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/W3 D2/LinkedList/LinkedList.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/W3 D2/LinkedList/Program.cs b/W3 D2/LinkedList/Program.cs new file mode 100644 index 0000000..2b8c385 --- /dev/null +++ b/W3 D2/LinkedList/Program.cs @@ -0,0 +1,25 @@ +public class Program +{ + static void Main() + { + LinkedList list = new(); + list.AddLast(2); + list.AddLast(3); + list.AddLast(4); + list.AddFirst(1); + list.AddLast(6); + LinkedListNode? node = list.Find(6); + list.AddBefore(node, 5); + PrintLinkedList(list, nameof(list)); + } + + static void PrintLinkedList(LinkedList list, string varName) + { + Console.Write(varName + ": "); + foreach (var item in list) + { + Console.Write($"{item} "); + } + Console.WriteLine(); + } +} \ No newline at end of file diff --git a/W3 D2/List/Car.cs b/W3 D2/List/Car.cs new file mode 100644 index 0000000..e4ced5b --- /dev/null +++ b/W3 D2/List/Car.cs @@ -0,0 +1,25 @@ +namespace List; + +public class Car +{ + private string _brandName; + private int _topSpeed; + + public string BrandName + { + get => _brandName; + set => _brandName = value; + } + + public int TopSpeed + { + get => _topSpeed; + set => _topSpeed = value; + } + + public Car(string brandName, int topSpeed) + { + _brandName = brandName; + _topSpeed = topSpeed; + } +} \ No newline at end of file diff --git a/W3 D2/List/List.csproj b/W3 D2/List/List.csproj new file mode 100644 index 0000000..b8e5116 --- /dev/null +++ b/W3 D2/List/List.csproj @@ -0,0 +1,8 @@ + + + Exe + net7.0 + enable + enable + + \ No newline at end of file diff --git a/W3 D2/List/Program.cs b/W3 D2/List/Program.cs new file mode 100644 index 0000000..9f01596 --- /dev/null +++ b/W3 D2/List/Program.cs @@ -0,0 +1,44 @@ +using List; + +public class Program +{ + static void Main() + { + List listOfNumbers = new List() {2, 4, 1, 9, 3, 5}; + PrintList(listOfNumbers, nameof(listOfNumbers)); + + // Ascending + listOfNumbers.Sort(); + PrintList(listOfNumbers, nameof(listOfNumbers)); + + listOfNumbers.Reverse(); + PrintList(listOfNumbers, nameof(listOfNumbers)); + + List cars = new List() {new Car("honda", 200), new Car("ferrari", 400), new Car("toyota", 150)}; + + Console.WriteLine(); + Console.WriteLine("Before sort"); + foreach (var car in cars) + { + Console.WriteLine($"{car.BrandName} - {car.TopSpeed} kmh"); + } + + Console.WriteLine(); + Console.WriteLine("After sort"); + cars.Sort((car1, car2) => car1.TopSpeed.CompareTo(car2.TopSpeed)); // Sort cars based on TopSpeed + foreach (var car in cars) + { + Console.WriteLine($"{car.BrandName} - {car.TopSpeed} kmh"); + } + } + + static void PrintList(List list, string varName) + { + Console.Write(varName + ": "); + foreach (var item in list) + { + Console.Write($"{item} "); + } + Console.WriteLine(); + } +} \ No newline at end of file