PI06 i PI06-1. Docker definitions for MSSQL and Postgres. Data seeder/generator for countries and people. Entity Framework example with variants for Postgres and MSSQL
This commit is contained in:
10
SomeOfCSharpFeatures/Delegates/Delegates.csproj
Normal file
10
SomeOfCSharpFeatures/Delegates/Delegates.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
26
SomeOfCSharpFeatures/Delegates/MathTool.cs
Normal file
26
SomeOfCSharpFeatures/Delegates/MathTool.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace Delegates;
|
||||
|
||||
public class MathTool
|
||||
{
|
||||
public static int Sum(int x, int y)
|
||||
{
|
||||
return x + y;
|
||||
}
|
||||
|
||||
public static int Diff(int x, int y)
|
||||
{
|
||||
return x - y;
|
||||
}
|
||||
|
||||
public static void PrintSquare(int x)
|
||||
{
|
||||
Console.WriteLine("x^2 = " + x * x);
|
||||
}
|
||||
|
||||
public static void PrintSquareRoot(int x)
|
||||
{
|
||||
Console.WriteLine("sqrt(x) = " + Math.Sqrt(x));
|
||||
}
|
||||
}
|
||||
31
SomeOfCSharpFeatures/Delegates/Program.cs
Normal file
31
SomeOfCSharpFeatures/Delegates/Program.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace Delegates;
|
||||
|
||||
class Program
|
||||
{
|
||||
public delegate int MathFunction(int a, int b);
|
||||
public delegate void PrintFunction(int n);
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int x = 16, y = 2;
|
||||
MathFunction mf = MathTool.Sum;
|
||||
Console.WriteLine("mf({0}, {1}) = {2}", x, y, mf(x, y));
|
||||
mf = MathTool.Diff;
|
||||
Console.WriteLine("mf({0}, {1}) = {2}", x, y, mf(x, y));
|
||||
PrintFunction pf = MathTool.PrintSquare;
|
||||
pf += MathTool.PrintSquareRoot;
|
||||
pf(x);
|
||||
#pragma warning disable CS8601 // Possible null reference assignment.
|
||||
pf -= MathTool.PrintSquare;
|
||||
#pragma warning restore CS8601 // Possible null reference assignment.
|
||||
Console.WriteLine();
|
||||
#pragma warning disable CS8602 // Dereference of a possibly null reference.
|
||||
pf(y); //instead of pragma pf?.Invoke(y); can be used
|
||||
#pragma warning restore CS8602 // Dereference of a possibly null reference.
|
||||
|
||||
Func<int, int, int> func = MathTool.Sum;
|
||||
Console.WriteLine("func({0}, {1}) = {2}", x, y, func(x, y));
|
||||
|
||||
Action<int> action = MathTool.PrintSquare;
|
||||
action(x);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user