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 |
Is datetime value type c#?
What are the types of operator?
What is a long in c#?
What is use of FormBoarderStyle Propertie
What is the use of system.environment class in c#.net?
can you allow a class to be inherited, but prevent the method from being over-ridden?
can we assign null value to value type in c#?
12 Answers Idea, Microsoft, Wipro,
if we inherit class in stack so object of stack will store in stack or heap? as class a { int s; public aa(){} } stack mystack:a { } mystack obj; ans: about obj
Explain about throw keyword?
10 Answers Emphasis, HCL, Satyam,
C# called c sharp why?
What is string class in c#?
What is form feed 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)