Posts

Lession 57: C# Dynamic type

Image
C# 4.0 (.NET 4.5) introduced a new type that avoids compile time type checking. You have learned about the implicitly typed variable-  var  in the previous section where the compiler assigns a specific type based on the value of the expression. A dynamic type escapes type checking at compile time; instead, it resolves type at run time.

Lession 56: C# Anonymous Type

Image
Anonymous type, as the name suggests, is a type that doesn't have any name. C# allows you to create an object with the  new  keyword without defining its class. The  implicitly typed variable- var  is used to hold the reference of anonymous types.

Lession 55: C# Extension Method

Image
Extension methods, as the name suggests, are additional methods. Extension methods allow you to inject additional methods without modifying, deriving or recompiling the original class, struct or interface. Extension methods can be added to your own custom class, .NET framework classes, or third party classes or interfaces. In the following example, IsGreaterThan() is an extension method for int type, which returns true if the value of the int variable is greater than the supplied integer parameter.

Lession 54: Predicate delegate in C#

A predicate is also a delegate like  Func  and  Action  delegates. It represents a method that contains a set of criteria and checks whether the passed parameter meets those criteria or not. A predicate delegate methods must take one input parameter and it then returns a boolean value - true or false. The Predicate delegate is defined in the System namespace as shown below: Predicate signature:  public   delegate   bool   Predicate < in  T>(T obj); Same as other delegate types, Predicate can also be used with any method, anonymous method or lambda expression.

Lession 53: Action Delegate

Action is also a delegate type defined in the System namespace. An Action type delegate is the same as  Func delegate except that the Action delegate doesn't return a value. In other words, an Action delegate can be used with a method that has a void return type. For example, the following delegate prints an int value.

Lession 52: Func delegate in C#

Image
We have learned in the previous section, that a  delegates  can be defined as shown below.