Explaining yield keyword in C#
<p>Could you explain me how 'yield' keyword works in regards to Enumerable? For ex. I can't understand how in the code below program returns an object of type IEnumerable:</p>

<pre><code>class Program
    {
        static IEnumerable&lt;T&gt; Merge&lt;T&gt;(IEnumerable&lt;T&gt; left, IEnumerable&lt;T&gt; right)
            where T: IComparable&lt;T&gt;
        {
            IEnumerator&lt;T&gt; l = left.GetEnumerator();
            IEnumerator&lt;T&gt; r = right.GetEnumerator();

            bool l_has_data = l.MoveNext();
            bool r_has_data = r.MoveNext();

            while (l_has_data || r_has_data)
            {
                if (!l_has_data &amp;&amp; r_has_data)
                {
                    yield return r.Current;
                    r_has_data = r.MoveNext();
                    continue;
                }
                if (!r_has_data &amp;&amp; l_has_data)
                {
                    yield return l.Current;
                    l_has_data = l.MoveNext();
                    continue;
                }

                int comp = l.Current.CompareTo(r.Current);
                if (comp &lt; 0)
                {
                    yield return l.Current;
                    l_has_data = l.MoveNext();
                }
                else if (comp &gt; 0)
                {
                    yield return r.Current;
                    r_has_data = r.MoveNext();
                }
                else
                {
                    yield return l.Current;
                    yield return r.Current;
                    l_has_data = l.MoveNext();
                    r_has_data = r.MoveNext();
                }
            }
        }
</code></pre>

<p>If i hover over '.Current' it says me that this 'Gets the element at the current position of the enumerator'.</p>
