khanalshree

Posts Tagged ‘mvc


Start mvc and get new key word yield.Which I never use in asp.net 3.5.So I search on google and find some thing interesting which I am going to post.
yield keyword is introduced by C# 2.0 in order to implement iteartion easier. On the other hand it has some disadventages. Let’s first look at the yield keyword.


public IEnumerable GetPowersofTwo()
{
for (int i = 1; i < 10; i++)
yield return (int)System.Math.Pow(2, i);
yield break;
}

yield is not a feature of the .Net runtime. It is just a C# language feature. During compilation Compiler converts yield method and its class to instances of IEnumerable and IEnumerator implemented classes.

Criticism of the keyword “yield”

“yield” has a couple of drawbacks first of all it is designed to simplify implementing iterations. But it can be used to write very ill designed code (like goto). But using it for other than the intended purpose will make your code hard to follow.

Second problem is that “yield” does not make sense in Object Oriented paradigm just like delegates.When Microsoft introduced C# they decided to use delegates as an event mechanism, instead of interfaces. Delegates are function pointers and have no meaning in OOP. A similar problem exists for yield too

Tags: , ,

Blog Stats

  • 10,673 hits

STATUS

ME

Me

ME

ME

ME