-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add W2 D3 projects (not finished yet)
- Loading branch information
Showing
18 changed files
with
384 additions
and
0 deletions.
There are no files selected for viewing
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
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
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> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using DelegatePubSub; | ||
public delegate void Publish(string x); | ||
public class Program | ||
{ | ||
static void Main() | ||
{ | ||
Youtuber yt = new(); | ||
Subscriber sub1 = new(); | ||
|
||
yt.AddSubscriber(sub1.Notify); | ||
yt.SendNotification(); | ||
|
||
yt.RemoveSubscriber(sub1.Notify); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace DelegatePubSub; | ||
public class Subscriber | ||
{ | ||
public void Notify(string message) | ||
{ | ||
Console.WriteLine(message); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace DelegatePubSub; | ||
public class Youtuber | ||
{ | ||
private Publish? _sub; | ||
public void SendNotification() | ||
{ | ||
if (_sub != null) | ||
{ | ||
_sub.Invoke("Notify"); | ||
} | ||
} | ||
|
||
public void AddSubscriber(Publish sub) | ||
{ | ||
if (_sub == null || !_sub.GetInvocationList().Contains(sub)) | ||
{ | ||
_sub += sub; | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Error: Subscriber already exist."); | ||
} | ||
} | ||
|
||
public void RemoveSubscriber(Publish sub) | ||
{ | ||
if (_sub != null) | ||
{ | ||
_sub -= sub; | ||
} else | ||
{ | ||
Console.WriteLine("Error: No subscriber."); | ||
} | ||
} | ||
} |
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
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> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
public delegate decimal Calculator(decimal a, decimal b); | ||
public class Program { | ||
static void Main() | ||
{ | ||
Calculator calc = Add; | ||
calc += Subtract; | ||
calc += Multiply; | ||
calc += Divide; | ||
|
||
Delegate[] del = calc.GetInvocationList(); | ||
List<decimal> results = new List<decimal>(); | ||
|
||
foreach (Calculator d in del) | ||
{ | ||
results.Add(d.Invoke(5.1M, 5.1M)); | ||
} | ||
|
||
foreach (decimal result in results) | ||
{ | ||
Console.WriteLine(result); | ||
} | ||
} | ||
|
||
static decimal Add(decimal a, decimal b) | ||
{ | ||
return a + b; | ||
} | ||
|
||
static decimal Subtract(decimal a, decimal b) | ||
{ | ||
return a - b; | ||
} | ||
|
||
static decimal Multiply(decimal a, decimal b) | ||
{ | ||
return a * b; | ||
} | ||
|
||
static decimal Divide(decimal a, decimal b) | ||
{ | ||
return a / b; | ||
} | ||
} |
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
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> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
Console.WriteLine("Hello, World!"); |
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
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> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using EventHandlerExample; | ||
public class Program | ||
{ | ||
static void Main() | ||
{ | ||
Youtuber yt1 = new Youtuber("Windah Basudara"); | ||
Subscriber sub1 = new Subscriber("Yusuf"); | ||
|
||
yt1.AddSubscriber(sub1.GetNotification); | ||
yt1.UploadVideo(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace EventHandlerExample; | ||
public class Subscriber | ||
{ | ||
private string? _name; | ||
|
||
public Subscriber(string name) | ||
{ | ||
_name = name; | ||
} | ||
|
||
public void GetNotification(object? sender, EventArgs e) | ||
{ | ||
|
||
Console.WriteLine($"{_name} is getting notification from Youtuber ({sender})."); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace EventHandlerExample; | ||
public class Youtuber | ||
{ | ||
private EventHandler? _sub; | ||
private string _name; | ||
|
||
public Youtuber(string name) | ||
{ | ||
_name = name; | ||
} | ||
|
||
public void AddSubscriber(EventHandler sub) | ||
{ | ||
if (_sub == null || !_sub.GetInvocationList().Contains(sub)) | ||
{ | ||
_sub += sub; | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Error: Subscriber already exist."); | ||
} | ||
} | ||
|
||
public void RemoveSubscriber(EventHandler sub) | ||
{ | ||
if (_sub != null) | ||
{ | ||
_sub -= sub; | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Error: No subscriber."); | ||
} | ||
} | ||
|
||
public void UploadVideo() | ||
{ | ||
Console.WriteLine("Video is being uploaded.."); | ||
Console.WriteLine("Video uploaded."); | ||
SendNotification(); | ||
} | ||
|
||
private void SendNotification() | ||
{ | ||
if (_sub != null) | ||
{ | ||
_sub.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
public override string ToString() | ||
{ | ||
return _name; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace EventHandlerGeneric; | ||
public class EventData : EventArgs | ||
{ | ||
public string? message; | ||
public int viewCount; | ||
} |
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
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> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using EventHandlerGeneric; | ||
|
||
public class Program | ||
{ | ||
static void Main() | ||
{ | ||
Youtuber yt = new Youtuber("Windah Basudara"); | ||
Subscriber sub1 = new Subscriber("Yusuf"); | ||
|
||
yt.AddSubscriber(sub1.GetNotification); | ||
yt.UploadVideo("Game Horror"); | ||
|
||
yt.AddViewCount(sub1.WatchVideo); | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace EventHandlerGeneric; | ||
public class Subscriber | ||
{ | ||
private string? _name; | ||
EventData data = new(); | ||
|
||
public Subscriber(string name) | ||
{ | ||
_name = name; | ||
} | ||
|
||
public void WatchVideo(object? sender, EventData e) | ||
{ | ||
Console.WriteLine($"{_name} is watching youtube video"); | ||
data.viewCount += 1; | ||
} | ||
|
||
public void GetNotification(object? sender, EventData e) | ||
{ | ||
Console.WriteLine(e.message); | ||
} | ||
|
||
// public void GetViewCount(object? sender, EventData e) | ||
// { | ||
// Console.WriteLine($"Youtube view count: {e.viewCount}"); | ||
// } | ||
} |
Oops, something went wrong.