Brushing up C# features ...



Recently, as a  part of the ASP.NET MVC 4 training I got an opportunity to brush up few C# features.

Lazy
Provides support for lazy initialization i.e. the object is created or instantiated at the last moment or only when it is needed. The value of the object can be accessed using Lazy.Value property.

dynamic keyword
dynamic keyword hints the compiler to skip the compile time type checking and defers the resolution until runtime. This means that the Visual Studio intellisense for the object defined using dynamic keyword will not be available.

dynamic obj = 1;

Expando object
Expando allows creation of an object with members that can be dynamically added and removed at run time. Here's an example:

dynamic person = new ExpandoObject();
person.Name = "nimish bhonsale";
var method = new Action((x)=> Console.Write(x));
person.Write = method;
person.Write(person.Name.ToString());

No comments:

Post a Comment