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 ?



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

Answer / 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

More C Sharp Interview Questions

write a program to find the biggest palindrome in the given string

0 Answers   Microsoft,


What is difference between "as" and "is" keyword?

1 Answers  


What is session variable in c#?

0 Answers  


What does public mean in c#?

0 Answers  


Explain the 3 types of properties in c# with an example?

0 Answers  


How many parameters can a method have c#?

0 Answers  


Why are there five tracing levels in System.Diagnostics.TraceSwitcher?

1 Answers  


If a.equals(b) is true then a.gethashcode & b.gethashcode must always return same hash code.

0 Answers  


List down the different ide’s provided by microsoft for c# development.

0 Answers  


What is a di class?

0 Answers  


i want o/p 011242110 in c# code.

0 Answers   TCS,


Does c# support const methods, properties, or events?

0 Answers  


Categories