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 |
What is the difference between constant and readonly in c#?
What is default constructor c#?
Explain the difference between the system.array.copyto() and system.array.clone()?
From a versioning perspective, what are the drawbacks of extending an interface as opposed to extending a class?
What are access modifiers in c#?
Can variables defined in interface. If yes how we can call/use it in class.
What are the problem with .NET generics?
What can you do as a .net developer?
What is access specifier in c#?
What are delegates in C#?
What is .net console?
What is null propagation 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)