What are anonymous methods ? why these methods are used and in what condition these methods are useful ?
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 |
How to rotate an Image in C#?
0 Answers Petranics Solutions,
What is parameter c#?
What is a collection class in c#?
windows c# using datagridview in edit form sql server
User's session is explicitly killed by which method ?
What is a console device?
What is class method?
Explain the process of abstraction with an example?
What is the diff between System.String and System.Text.StringBuilder classes?
What is an ienumerable in c#?
When should I throw an exception?
What is indexers in C#
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)