yield keyword

June 17, 2007

“Yield”=> Contextual keyword introduced to c# 2.0. It is important for “lazy evaluation” and the performance of queries in LINQ. Yield can be used as a variable name in C#. When put before return it becomes a keyword.

“Lazy evaluation”=>Lazy evaluation means that until you iterate over the result of the query, the source of the query is not iterated.

Advantages=>yield allows one enumerable class to be implemented in terms of another. This enables the delay of execution of queries until the latest possible moment, skipping the generation of intermediate results that would drastically reduce performance. The query operators in LINQ operate on sequence. The result of a query is often another sequence.


Var keyword in orcas

June 17, 2007

What is it??
As the name suggests, “var” keyword can be used in place of type name in local variable declarations.

Is it a untyped variable reference??
No, it is not a late bound or untyped variable reference. It always creates a strongly typed variable reference. When the var type variable is declared, the compiler infers the type of the variable from expression used to initialize the variable when it is first declared. for example, var name = “yoganand”; will be inferred as string name=”yoganand”;.The CLR actually never knows that the var keyword is being used – from its perspective there is absolutely no difference between the above two declarations but in the first declaration, the compiler does the work of inferring and declaring the type name.

What types can be referenced with var keyword??
Var keyword can be used to reference any type(anonymous and explicitly declared types) in C#.
Even custom types we define can be referenced.Var keyword produces strongly typed declarations and hence the compiler needs to be able to infer the type based on its usage. So, var definition should always be initialized, produces a compiler error otherwise.

Silverlight- Microsoft’s answer to flash

May 14, 2007

From Java vs .NET framework to ipod vs zune to silverlight vs flash… Microsoft always has the knack of coming up with strong opponents to topple the market leaders. By now, as all of us know, Silverlight is no different. I didn’t get my hands dirty with silverlight yet and so please correct me if I am wrong.

Silverlight–What is it?

Silverlight is a cross- browser, cross-platform plug in that allows developers to create .NET applications(C# etc), for delivering media and rich interactive applications (RIAs) for the Web.

The first thing I liked about it is its 1 MB size to download. Silverlight is a lightweight subset of XAML. By separating markup (XAML) from code, Silverlight provides a familiar web metaphor for developers. XAML can be embedded directly witihin an HTML file or can be kept separate. Microsoft is also introducing a new drm system, called PlayReady. The current version of Flash cannot protect content at this time. It is very easy for an ASP.NET AJAX developer to add Silverlight content.

How and why silverlight would succeed?

With all their experience in building user friendly tools, microsoft can avoid the mistakes adobe has committed and can come up with a much better toolset. Their expression suite that I saw in one of the videos is pretty impressive.

Microsoft should and will pour money in silverlight’s promotion. Given their experience, this shouldn’t be a problem.

One of the major problems with microsoft is that it isn’t cross-platform. It seems to have sorted it out with silverlight.

As of now, silverlight looks likes a clone of flash. They need to improve their feature set in future.

To conclude, a lot of developers(around 84%) doing RIAs are using adobe applications now. Silverlight is a welcome change and good competitior but I still think it has a long way to go to dethrone flash completely.

C# 3.0(Orcas) Language Features– A overkill?

May 6, 2007

The three new language features in C# 3.0 :

  • Automatic Properties
  • Object Initializers, and
  • Collection Initializers

Read this blog by Scott Guthrie.

Private int _age;

Public int Age

{ get{return _age;}

set{_age = value;}}

Firstly, by automatic properties, we can shorten a code sample above to the one below.

Public int Age{get; set;}

At first look, I thought this would be a elegant way to keep my code terse and simple. But, is this intuitive? Does a new developer find it easy to see a private field and public property in it? Also, for people like me who use add-ins like resharper for visual studio.NET, properties are automatically created. I think its simplicity and intuitiveness is lost with these automatic properties.

Unlike Automatic properties, object and collection initializers are awesome features to write concise and intuitive code.

Employee employee = new Employee{ id = “007” name = “bond”} ;

EmployeeList employeeList = new EmployeeList{new Employee{ id = “007” name = “bond”} } ;

The above one liners not only conserve time and space but are more intuitive and less error prone.

Hello world!

April 9, 2007

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!