Posts

Showing posts with the label Action

C# Delegates,Action,Func,Lamdas

In this blog, we will discuss Action delegate, Func delegate, and Lamdas. Let's start with a definition of delegate. Delegate: A delegate is a type that safely encapsulates a method, similar to a function pointer in C++.C# delegates are object-oriented, type-safe and secure. The type of delegate is defined by the name of the delegate. Action Delegate: - Action(Of T) delegate to pass a method as a parameter without explicitly declaring a custom delegate.We don't need to declare a delegate. The compiler is smart enough to figure out the proper types. The limitation is that corresponding method action must not return a value. Example to display Fahrenheit and Celsius using Action :-  public static void Main(string[] args) {            Action displayFarenheit = delegate(double celsius)             {                 Console.WriteLine((celsius * 9.0/5.0 ) + 32.0); ...