Skip to content

Commit 8e6e88c

Browse files
authored
Multicast Delegates
1 parent 7293d7b commit 8e6e88c

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

CsharpLangExamples.sln

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheLockStatement", "TheLock
7171
EndProject
7272
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserDefinedConversionOperators", "UserDefinedConversionOperators\UserDefinedConversionOperators.csproj", "{CCD3ED3C-6C34-4F9E-A422-79479625FC75}"
7373
EndProject
74+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MulticastDelegates", "MulticastDelegates\MulticastDelegates.csproj", "{CA03B883-1055-404B-920C-E52B8D3F4DB0}"
75+
EndProject
7476
Global
7577
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7678
Debug|Any CPU = Debug|Any CPU
@@ -213,6 +215,10 @@ Global
213215
{CCD3ED3C-6C34-4F9E-A422-79479625FC75}.Debug|Any CPU.Build.0 = Debug|Any CPU
214216
{CCD3ED3C-6C34-4F9E-A422-79479625FC75}.Release|Any CPU.ActiveCfg = Release|Any CPU
215217
{CCD3ED3C-6C34-4F9E-A422-79479625FC75}.Release|Any CPU.Build.0 = Release|Any CPU
218+
{CA03B883-1055-404B-920C-E52B8D3F4DB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
219+
{CA03B883-1055-404B-920C-E52B8D3F4DB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
220+
{CA03B883-1055-404B-920C-E52B8D3F4DB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
221+
{CA03B883-1055-404B-920C-E52B8D3F4DB0}.Release|Any CPU.Build.0 = Release|Any CPU
216222
EndGlobalSection
217223
GlobalSection(SolutionProperties) = preSolution
218224
HideSolutionNode = FALSE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

MulticastDelegates/Program.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
internal class Program
2+
{
3+
// How to combine delegates (Multicast Delegates) (C# Programming Guide)
4+
// https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/how-to-combine-delegates-multicast-delegates
5+
6+
// Delegates, Multicast delegates and Events in C# - Notes
7+
// https://www.codeproject.com/Articles/1061085/Delegates-Multicast-delegates-and-Events-in-Csharp
8+
9+
static void Hello(string s) => Console.WriteLine("Hello, {0}", s);
10+
static void GoodBye(string s) => Console.WriteLine("Goodbye, {0}", s);
11+
12+
private static void Main(string[] args)
13+
{
14+
CustomCallback hello, goodbye, multiDelegation;
15+
16+
hello = new CustomCallback(Hello);
17+
goodbye = new CustomCallback(GoodBye);
18+
19+
multiDelegation = hello + goodbye;
20+
21+
multiDelegation("İbrahim");
22+
}
23+
}
24+
25+
delegate void CustomCallback(String s);

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ Examples of C# programming, with the goal of tracking and staying up-to-date wit
5353
* C# 6
5454
* [Using static directive](UsingStaticDirective/)
5555
* [Collection initializers](CollectionInitializers/)
56-
* C# 4
56+
* C# 4 & others
5757
* [Dynamic types](DynamicTypes/)
58+
* [Multicast Delegates](MulticastDelegates/)
5859

5960
## Notes
6061
- [Which C# version is included in which framework version?](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version)

0 commit comments

Comments
 (0)