diff --git a/MySolution/ConsoleApp/.vscode/launch.json b/MySolution/ConsoleApp/.vscode/launch.json new file mode 100644 index 0000000..396234c --- /dev/null +++ b/MySolution/ConsoleApp/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/net7.0/ConsoleApp.dll", + "args": [], + "cwd": "${workspaceFolder}", + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/MySolution/ConsoleApp/.vscode/tasks.json b/MySolution/ConsoleApp/.vscode/tasks.json new file mode 100644 index 0000000..b2b3390 --- /dev/null +++ b/MySolution/ConsoleApp/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/ConsoleApp.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/ConsoleApp.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/ConsoleApp.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/MySolution/ConsoleApp/ConsoleApp.csproj b/MySolution/ConsoleApp/ConsoleApp.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/MySolution/ConsoleApp/ConsoleApp.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/MySolution/ConsoleApp/Program.cs b/MySolution/ConsoleApp/Program.cs new file mode 100644 index 0000000..1e4a126 --- /dev/null +++ b/MySolution/ConsoleApp/Program.cs @@ -0,0 +1,30 @@ +using Samples; + +namespace ConsoleApp; +class Program +{ + static void Main(string[] args) + { + #region Delegate + + // CalculateSample.Sample(); + // MessagePrinterSample.Sample(); + + #endregion + + + #region Callback + + // StringLength.Sample(); + + #endregion + + + #region Event + + EventSample.Sample(); + + #endregion + + } +} diff --git a/MySolution/ConsoleApp/Samples/CalculateSample.cs b/MySolution/ConsoleApp/Samples/CalculateSample.cs new file mode 100644 index 0000000..c9e69ca --- /dev/null +++ b/MySolution/ConsoleApp/Samples/CalculateSample.cs @@ -0,0 +1,28 @@ +using System; + +namespace Samples +{ + class CalculateSample + { + private delegate int Calculate(int x, int y); + + public static int Add(int x, int y) + { + return x + y; + } + + public static int Subtract(int x, int y) + { + return x - y; + } + + public static void Sample() + { + Calculate calc1 = Add; + Calculate calc2 = Subtract; + + Console.WriteLine(calc1(10, 5)); + Console.WriteLine(calc2(10, 5)); + } + } +} \ No newline at end of file diff --git a/MySolution/ConsoleApp/Samples/EventSample.cs b/MySolution/ConsoleApp/Samples/EventSample.cs new file mode 100644 index 0000000..38df234 --- /dev/null +++ b/MySolution/ConsoleApp/Samples/EventSample.cs @@ -0,0 +1,33 @@ +using System; + +namespace Samples +{ + public delegate void CustomEventHandler(object sender, EventArgs e); + + class EventSample + { + public static void Sample() + { + Button button = new Button(); + button.Click += new CustomEventHandler(Button_Click); + + button.OnClick(); + } + + private static void Button_Click(object sender, EventArgs e) + { + System.Console.WriteLine("Button clicked!"); + } + } + + class Button + { + public event CustomEventHandler Click; + + public void OnClick() + { + if (Click != null) + Click(this, EventArgs.Empty); + } + } +} \ No newline at end of file diff --git a/MySolution/ConsoleApp/Samples/MessagePrinterSample.cs b/MySolution/ConsoleApp/Samples/MessagePrinterSample.cs new file mode 100644 index 0000000..031934c --- /dev/null +++ b/MySolution/ConsoleApp/Samples/MessagePrinterSample.cs @@ -0,0 +1,29 @@ +using System; +using System.Diagnostics; +using System.Threading.Tasks; + +namespace Samples +{ + class MessagePrinterSample + { + private delegate Task MessagePrinter(string message); + + private static async Task PrintMessageAsync(string message) + { + await Task.Delay(1000); + Console.WriteLine(message); + } + + public static void Sample() + { + MessagePrinter printer = PrintMessageAsync; + Console.WriteLine("Start..."); + + printer("This is first message"); + printer("This is second message"); + printer("This is third message"); + + Console.WriteLine("Finish..."); + } + } +} \ No newline at end of file diff --git a/MySolution/ConsoleApp/Samples/StringLength.cs b/MySolution/ConsoleApp/Samples/StringLength.cs new file mode 100644 index 0000000..03e1ea5 --- /dev/null +++ b/MySolution/ConsoleApp/Samples/StringLength.cs @@ -0,0 +1,40 @@ +using System; + +namespace Samples +{ + class StringLength + { + public static void Sample() + { + string[] words = new string[] + { + "Apple", + "Banana", + "Cherry", + "Pear", + }; + + CalculateStringLength(words, PrintStingLength); + } + + private static void CalculateStringLength(string[] words, Action callback) + { + int[] lengths = new int[words.Length]; + for (int i = 0; i < words.Length; i++) + { + lengths[i] = words[i].Length; + } + + if (callback != null) + callback(lengths); + } + + private static void PrintStingLength(int[] lengths) + { + foreach (int length in lengths) + { + Console.WriteLine(length); + } + } + } +} \ No newline at end of file diff --git a/MySolution/MySolution.sln b/MySolution/MySolution.sln new file mode 100644 index 0000000..f84d375 --- /dev/null +++ b/MySolution/MySolution.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{AF3FAEF8-E438-4E8C-9A99-C0A94649EFEE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AF3FAEF8-E438-4E8C-9A99-C0A94649EFEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF3FAEF8-E438-4E8C-9A99-C0A94649EFEE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF3FAEF8-E438-4E8C-9A99-C0A94649EFEE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF3FAEF8-E438-4E8C-9A99-C0A94649EFEE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal