parent
ff8222b942
commit
2a2319833a
@ -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" |
||||||
|
} |
||||||
|
] |
||||||
|
} |
@ -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" |
||||||
|
} |
||||||
|
] |
||||||
|
} |
@ -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> |
@ -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)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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..."); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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<int[]> 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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue