https://github.com/zyn10/anonymus_methods_in_csharp
Anonymous Methods practice in csharp
https://github.com/zyn10/anonymus_methods_in_csharp
anonymous-method csharp practice-programming
Last synced: about 1 month ago
JSON representation
Anonymous Methods practice in csharp
- Host: GitHub
- URL: https://github.com/zyn10/anonymus_methods_in_csharp
- Owner: zyn10
- Created: 2022-10-02T05:27:25.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-06T20:09:10.000Z (over 3 years ago)
- Last Synced: 2025-12-29T00:09:49.906Z (6 months ago)
- Topics: anonymous-method, csharp, practice-programming
- Language: C#
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Anonymous Methods
We discussed that delegates are used to reference any methods that
has the same signature as that of the delegate.
In other words, you can call a method that can be referenced by a
delegate using that delegate object.
Anonymous methods provide a technique to pass a code block as a
delegate parameter.
Anonymous methods are the methods without a name, just the body.
Writing an Anonymous Method
Anonymous methods are declared with the creation of the delegate
instance, with a delegate keyword.
delegate void NumberChanger(int n);
NumberChanger nc = delegate(int x) {
Console.WriteLine("Anonymous Method: {0}", x);
};
The code block Console.WriteLine("Anonymous Method: {0}", x); is
the body of the anonymous method.
The delegate could be called both with anonymous methods as well
as named methods in the same way, i.e., by passing the method
parameters to the delegate object.