Skip to content

Commit

Permalink
Add W2 D2 projects
Browse files Browse the repository at this point in the history
  • Loading branch information
cvpfus committed Sep 12, 2023
1 parent 91e73d8 commit f97bd77
Show file tree
Hide file tree
Showing 18 changed files with 299 additions and 2 deletions.
37 changes: 37 additions & 0 deletions FormulatrixBootcamp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreRef", "W2 D1\MoreRef\Mo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enum", "W2 D1\Enum\Enum.csproj", "{3B6CBE35-FC4D-4AFC-A6F9-09A7DB9B4378}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "W2 D2", "W2 D2", "{747633C8-D663-4492-9F60-E01A9F09A1CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericConstraints", "W2 D2\GenericConstraints\GenericConstraints.csproj", "{D134C540-432E-414B-82F4-72D084C20224}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericCollection", "W2 D2\GenericCollection\GenericCollection.csproj", "{71C8B23F-6C05-4DE7-8ECA-5C4303AB402A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericClass", "W2 D2\GenericClass\GenericClass.csproj", "{367138CF-7021-4354-B364-6A674AA8E4D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NonGenericCollection", "W2 D2\NonGenericCollection\NonGenericCollection.csproj", "{51504E3A-4A98-45D9-B64B-C657E7CC95B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Delegate", "W2 D2\Delegate\Delegate.csproj", "{8CBF3A9D-D792-4ECC-92A3-0E2782673234}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -157,6 +169,26 @@ Global
{3B6CBE35-FC4D-4AFC-A6F9-09A7DB9B4378}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B6CBE35-FC4D-4AFC-A6F9-09A7DB9B4378}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B6CBE35-FC4D-4AFC-A6F9-09A7DB9B4378}.Release|Any CPU.Build.0 = Release|Any CPU
{D134C540-432E-414B-82F4-72D084C20224}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D134C540-432E-414B-82F4-72D084C20224}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D134C540-432E-414B-82F4-72D084C20224}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D134C540-432E-414B-82F4-72D084C20224}.Release|Any CPU.Build.0 = Release|Any CPU
{71C8B23F-6C05-4DE7-8ECA-5C4303AB402A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71C8B23F-6C05-4DE7-8ECA-5C4303AB402A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71C8B23F-6C05-4DE7-8ECA-5C4303AB402A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71C8B23F-6C05-4DE7-8ECA-5C4303AB402A}.Release|Any CPU.Build.0 = Release|Any CPU
{367138CF-7021-4354-B364-6A674AA8E4D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{367138CF-7021-4354-B364-6A674AA8E4D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{367138CF-7021-4354-B364-6A674AA8E4D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{367138CF-7021-4354-B364-6A674AA8E4D5}.Release|Any CPU.Build.0 = Release|Any CPU
{51504E3A-4A98-45D9-B64B-C657E7CC95B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51504E3A-4A98-45D9-B64B-C657E7CC95B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51504E3A-4A98-45D9-B64B-C657E7CC95B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51504E3A-4A98-45D9-B64B-C657E7CC95B9}.Release|Any CPU.Build.0 = Release|Any CPU
{8CBF3A9D-D792-4ECC-92A3-0E2782673234}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8CBF3A9D-D792-4ECC-92A3-0E2782673234}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CBF3A9D-D792-4ECC-92A3-0E2782673234}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CBF3A9D-D792-4ECC-92A3-0E2782673234}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -185,5 +217,10 @@ Global
{0D3E0858-A87D-4254-9192-25510F91A630} = {4AA51D7D-BA22-4F16-A2A3-8BD526E4CE19}
{C4365CA5-CA1C-47D8-89D8-C03E16A82144} = {4AA51D7D-BA22-4F16-A2A3-8BD526E4CE19}
{3B6CBE35-FC4D-4AFC-A6F9-09A7DB9B4378} = {4AA51D7D-BA22-4F16-A2A3-8BD526E4CE19}
{D134C540-432E-414B-82F4-72D084C20224} = {747633C8-D663-4492-9F60-E01A9F09A1CA}
{71C8B23F-6C05-4DE7-8ECA-5C4303AB402A} = {747633C8-D663-4492-9F60-E01A9F09A1CA}
{367138CF-7021-4354-B364-6A674AA8E4D5} = {747633C8-D663-4492-9F60-E01A9F09A1CA}
{51504E3A-4A98-45D9-B64B-C657E7CC95B9} = {747633C8-D663-4492-9F60-E01A9F09A1CA}
{8CBF3A9D-D792-4ECC-92A3-0E2782673234} = {747633C8-D663-4492-9F60-E01A9F09A1CA}
EndGlobalSection
EndGlobal
3 changes: 1 addition & 2 deletions W2 D1/Enum/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using Difficulty;
using Difficulty;

public class Program
{
Expand Down
10 changes: 10 additions & 0 deletions W2 D2/Delegate/Delegate.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
18 changes: 18 additions & 0 deletions W2 D2/Delegate/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Program
{
// signature: same return type & parameter
public delegate void MyDelegate(string text);
static void Main()
{
MyDelegate d = Print;

// two ways of calling or invoking delegate
d.Invoke("Hello world");
d("Hello world");

}
static void Print(string text)
{
Console.WriteLine(text);
}
}
29 changes: 29 additions & 0 deletions W2 D2/GenericClass/Car.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace GenericClass;
public class Car<T1, T2>
where T1 : class
where T2 : struct
{
private T1 _t1;
private T2 _t2;
public Car(T1 t1, T2 t2)
{
_t1 = t1;
_t2 = t2;
}
public T1 GetEngine()
{
return _t1;
}
public T2 GetTopSpeed()
{
return _t2;
}
public void SetEngine(T1 t1)
{
_t1 = t1;
}
public void SetTopSpeed(T2 t2)
{
_t2 = t2;
}
}
7 changes: 7 additions & 0 deletions W2 D2/GenericClass/EngineEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace GenericClass;
public enum EngineEnum
{
Diesel = 1,
Electric,
Jet
}
8 changes: 8 additions & 0 deletions W2 D2/GenericClass/GenericClass.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions W2 D2/GenericClass/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using GenericClass;

public class Program
{
static void Main()
{
Car<Enum, int> car1 = new Car<Enum, int>(EngineEnum.Electric, 300);
Console.WriteLine(car1.GetEngine());
car1.SetEngine(EngineEnum.Jet);
Console.WriteLine(car1.GetEngine());

Console.WriteLine(car1.GetTopSpeed());
car1.SetTopSpeed(900);
Console.WriteLine(car1.GetTopSpeed());
}
}
8 changes: 8 additions & 0 deletions W2 D2/GenericCollection/BrandEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace GenericCollection;

public enum BrandEnum
{
Toyota = 1,
Honda,
Ferrari
}
21 changes: 21 additions & 0 deletions W2 D2/GenericCollection/Car.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace GenericCollection;
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;
}
}
8 changes: 8 additions & 0 deletions W2 D2/GenericCollection/GenericCollection.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
47 changes: 47 additions & 0 deletions W2 D2/GenericCollection/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using GenericCollection;

public class Program
{
static void Main()
{
List<int> list = new List<int>
{
1,
2,
3,
4
};

foreach (var l in list)
{
Console.WriteLine(l);
}

List<Car> carList = new List<Car>
{
new Car("Honda", 300),
new Car("Toyota", 200),
new Car("Ferrari", 500)
};
carList[0].TopSpeed = 200;
carList[1].BrandName = "Tayo";

foreach (var c in carList)
{
Console.WriteLine($"{c.BrandName} has top speed of {c.TopSpeed} kmh.");
}

Dictionary<int, Car> dict = new Dictionary<int, Car>
{
{ (int)BrandEnum.Honda, new Car(BrandEnum.Honda.ToString(), 300) },
{ (int)BrandEnum.Toyota, new Car(BrandEnum.Toyota.ToString(), 200) },
{ (int)BrandEnum.Ferrari, new Car(BrandEnum.Ferrari.ToString(), 500) },
// { (int)BrandEnum.Ferrari, new Car(BrandEnum.Ferrari.ToString(), 500) } // Exception, An item with the same key has already been added. Key: 3
};

foreach (var d in dict)
{
Console.WriteLine($"{d.Value.BrandName} has top speed of {d.Value.TopSpeed} kmh.");
}
}
}
28 changes: 28 additions & 0 deletions W2 D2/GenericConstraints/Car.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace GenericConstraints;
public class Car : IEngine
{
private string? _carName;
public string? CarName
{
get => _carName;
set => _carName = value;
}

// Generic method
public void GetInfo<T>(T t) where T : class
{
Console.WriteLine("Info 1: " + t);
}
// Generic method
public void GetInfo<T1, T2>(T1 t1, T2 t2)
where T1 : class
where T2 : struct
{
Console.WriteLine("Info 1: " + t1);
Console.WriteLine("Info 2: " + t2);
}
public void RunEngine()
{
Console.WriteLine("Engine is running");
}
}
10 changes: 10 additions & 0 deletions W2 D2/GenericConstraints/GenericConstraints.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions W2 D2/GenericConstraints/IEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace GenericConstraints;
public interface IEngine
{
void RunEngine();
}
13 changes: 13 additions & 0 deletions W2 D2/GenericConstraints/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using GenericConstraints;

public static class Program
{
static void Main()
{
Car car = new();
car.CarName = "Toyota";
car.GetInfo(car.CarName);
car.GetInfo("Honda", 200);
// car.GetInfo(200, "Honda"); // <- error, first param should be class & second param should be struct
}
}
10 changes: 10 additions & 0 deletions W2 D2/NonGenericCollection/NonGenericCollection.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
23 changes: 23 additions & 0 deletions W2 D2/NonGenericCollection/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections;

public class Program
{
static void Main()
{
// ArrayList accepts all objects, it is not safety collection.
ArrayList arrList = new ArrayList();
arrList.Add(new Class1());
arrList.Add(3);
arrList.Add("abcdef");
((Class1)arrList[0]).Method1();
// ((Class1)arrList[1]).Method1(); // Unable to cast object of type 'System.Int32' to type 'Class1'.
}
}

public class Class1
{
public void Method1()
{
Console.WriteLine("Hi");
}
}

0 comments on commit f97bd77

Please sign in to comment.