Question: After almost 4 years of experience, I haven't seen a code where **yield** keyword is used. Can somebody show me a practical usage (along explanation) of this keyword, and if so, aren't there other ways easier to fullfill what it can do?

Answer: 
A practical example may be found here: 

<http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html>

There are a number of advantages of using yield over standard code:

* If the iterator is used to build a list then you can yield the return and the caller can **decide** whether he wants that result in a list, or not.
* The caller may also decide to cancel the iteration for a reason that is outside of the scope of what you are doing in the iteration.
* Code is a bit shorter.

However, as Jan\_V said (just beat me to it by a few seconds :-) you can live without it because internally the compiler will produce code almost identical in both cases.
Although the merging case has already been covered in the accepted answer, let me show you the yield-merge params extension method™:

```
public static IEnumerable<T> AppendParams<T>(this IEnumerable<T> a, params T[] b)
{
    foreach (var el in a) yield return el;
    foreach (var el in b) yield return el;
}

```

I use this to build packets of a network protocol:

```
static byte[] MakeCommandPacket(string cmd)
{
    return
        header
        .AppendParams<byte>(0, 0, 1, 0, 0, 1, 0x92, 0, 0, 0, 0)
        .AppendAscii(cmd)
        .MarkLength()
        .MarkChecksum()
        .ToArray();
}

```

The `MarkChecksum` method, for example, looks like this. And it has a `yield`, too:

```
public static IEnumerable<byte> MarkChecksum(this IEnumerable<byte> data, int pos = 6)
{
    foreach (byte b in data)
    {
        yield return pos-- == 0 ? (byte)data.Sum(z => z) : b;
    }
}

```

But be careful when using aggregate methods like Sum() in an enumeration method as they trigger a separate enumeration process.