Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

coding for delegates?

Answer Posted / dotnet user

using System;
// Declare delegate -- defines required signature:
delegate void SampleDelegate(string message);

class MainClass
{
// Regular method that matches signature:
static void SampleDelegateMethod(string message)
{
Console.WriteLine(message);
}

static void Main()
{
// Instantiate delegate with named method:
SampleDelegate d1 = SampleDelegateMethod;
// Instantiate delegate with anonymous method:
SampleDelegate d2 = delegate(string message)
{
Console.WriteLine(message);
};

// Invoke delegate d1:
d1("Hello");
// Invoke delegate d2:
d2(" World");
}
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the difference between the debug class and trace class?

858


How does foreach loop work in c#?

915


Is string mutable in c#?

824


Between windows authentication and sql server authentication, which one is trusted and which one is untrusted?

927


What does the initial catalog parameter define in the connection string?

877


Can extension methods access private members?

868


Explain “static” keyword in c#?

841


What is difference between association, aggregation and inheritance relationships?

875


What is the implicit name and type of the parameter that gets passed into the class set method?

834


Write a sample code to write the contents to text file in c#?

856


Which debugging tools you can use in the .NET ssSDK?

941


What are anonymous types in c#?

850


What is keywords in c#?

847


Which are the loop types available in c#?

903


What are the namespace level elements?

910