You are on page 1of 1

5/9/2015

C#ProgramtoCreateAnonymousMethodSanfoundry

thecoding overhead in instantiating delegates because a separate method need not be


created.

Here is source code of the C# Program to Create Anonymous Method. The C#


program is successfully compiled and executed with Microsoft Visual Studio. The
programoutputisalsoshownbelow.
1. /*
2. *C#ProgramtoCreateAnonymousMethod
3. */
4. usingSystem;
5. delegatevoidPrint(strings);
6. classTestClass
7. {
8. staticvoidMain()
9. {
10.Printobj=delegate(stringj)
11.{
12.System.Console.WriteLine(j);
13.};
14.obj("DelegateUsingtheAnonymousMethod");
15.obj=newPrint(TestClass.named);
16.obj("DelegateUsingtheNamedMethod");
17.Console.Read();
18.}
19.staticvoidnamed(stringk)
20.{
21.System.Console.WriteLine(k);
22.}
23.
24.}

HereistheoutputoftheC#Program:
DelegateUsingtheAnonymousMethod
DelegateUsingtheNamedMethod

SanfoundryGlobalEducation&LearningSeries1000C#Programs.
If you wish to look at all C# Programming examples, go to 1000 C# Programs
(http://www.sanfoundry.com/csharpprogrammingexamples/).

IfyoulikedthisC#Program,kindlyshare,recommendorlikebelow!
Like

0
0

Tweet
Share

You might also like