Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions csharp/language-reference/operators/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace operators
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("============== - operator examples =============");
SubtractionOperator.Examples();
Console.WriteLine();
}
}
}
58 changes: 58 additions & 0 deletions csharp/language-reference/operators/SubtractionOperator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;

namespace operators
{
public static class SubtractionOperator
{
public static void Examples()
{
DelegateRemoval();
SubtractAndAssign();
}

private static void DelegateRemoval()
{
// <SnippetDelegateRemoval>
Action a = () => Console.Write("a");
Action b = () => Console.Write("b");

var abbaab = a + b + b + a + a + b;
abbaab(); // output: abbaab
Console.WriteLine();

var ab = a + b;
var abba = abbaab - ab;
abba(); // output: abba
Console.WriteLine();

var aba = a + b + a;
var first = abbaab - aba;
first(); // output: abbaab
Console.WriteLine();

var nihil = abbaab - abbaab;
Console.WriteLine(nihil is null); // output: True
// </SnippetDelegateRemoval>
}

private static void SubtractAndAssign()
{
// <SnippetSubtractAndAssign>
int i = 5;
i -= 9;
Console.WriteLine(i);
// Output: -4

Action a = () => Console.Write("a");
Action b = () => Console.Write("b");
var printer = a + b + a;
printer(); // output: aba

Console.WriteLine();
printer -= a;
printer(); // output: ab
// </SnippetSubtractAndAssign>
Console.WriteLine();
}
}
}
14 changes: 14 additions & 0 deletions csharp/language-reference/operators/operators.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<LangVersion>7.3</LangVersion>
<StartupObject>operators.Program</StartupObject>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

</Project>