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...

What are anonymous methods ? why these methods are used and in what condition these methods are useful ?

Answer Posted / sudhir sheoran

Anonymous methods are used for making delegates
use simple. In this in spite of declaring a separate
method and then assigning a delegate to it we can
directly write inline code during the declaration
of delegate. E.g;

class Program
{
public delegate bool CalculatorDelegate(int number);
static void Main(string[] args)
{
CalculatorDelegate calDel = numberGreaterThanFive;
bool value = calDel.Invoke(4);
}
public static bool numberGreaterThanFive(int number)
{
if (number > 5)
{
return true
}
return false;
}
}

Now using Anonymous method and delegate :

class Program
{
public delegate bool CalculatorDelegate(int number);
static void Main(string[] args
{
CalculatorDelegate caldel =
new CalculatorDelegate(x => x > 5);

bool value = caldel.Invoke(3);
}

}

So code reduced to much extent. No need to define separate functions

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is learning c# hard?

916


You have got 1 million parking slots. At a time a parking slot can be free or not. To get next slot easily which data structure to implement?

1078


What is the difference between icomparer and icomparable in c#?

940


What do you mean by the delegate in c#?

912


What are properties in c#. Explain with an example?

913


What are Types of assemblies that can be created in dotnet

1033


What do you mean by synchronous and asynchronous operations?

977


What are floating point numbers?

997


When should I use static in C#?

981


What is out in c#?

925


What is dbml file in c#?

1001


What is difference between const and static in c#?

991


Why would you use a class property in c#?

918


What is the use of static members with example using c#.net.

918


What are the 4 pillars of any object oriented programming language?

883