title: Passing a single item as IEnumerable<T>
body: <p>Is there a common way to pass a single item of type <code>T</code> to a method which expects an  <code>IEnumerable&lt;T&gt;</code> parameter? Language is C#, framework version 2.0.</p>
  
  <p>Currently I am using a helper method (it's .Net 2.0, so I have a whole bunch of casting/projecting helper methods similar to LINQ), but this just seems silly:</p>
  
  <pre><code>public static class IEnumerableExt
  {
      // usage: IEnumerableExt.FromSingleItem(someObject);
      public static IEnumerable&lt;T&gt; FromSingleItem&lt;T&gt;(T item)
      {
          yield return item; 
      }
  }
  </code></pre>
  
  <p>Other way would of course be to create and populate a <code>List&lt;T&gt;</code> or an <code>Array</code> and pass it instead of <code>IEnumerable&lt;T&gt;</code>.</p>
  
  <p><strong>[Edit]</strong> As an extension method it might be named:</p>
  
  <pre><code>public static class IEnumerableExt
  {
      // usage: someObject.SingleItemAsEnumerable();
      public static IEnumerable&lt;T&gt; SingleItemAsEnumerable&lt;T&gt;(this T item)
      {
          yield return item; 
      }
  }
  </code></pre>
  
  <p>Am I missing something here?</p>
  
  <p><strong>[Edit2]</strong> We found <code>someObject.Yield()</code> (as @Peter suggested in the comments below) to be the best name for this extension method, mainly for brevity, so here it is along with the XML comment if anyone wants to grab it:</p>
  
  <pre><code>public static class IEnumerableExt
  {
      /// &lt;summary&gt;
      /// Wraps this object instance into an IEnumerable&amp;lt;T&amp;gt;
      /// consisting of a single item.
      /// &lt;/summary&gt;
      /// &lt;typeparam name="T"&gt; Type of the object. &lt;/typeparam&gt;
      /// &lt;param name="item"&gt; The instance that will be wrapped. &lt;/param&gt;
      /// &lt;returns&gt; An IEnumerable&amp;lt;T&amp;gt; consisting of a single item. &lt;/returns&gt;
      public static IEnumerable&lt;T&gt; Yield&lt;T&gt;(this T item)
      {
          yield return item;
      }
  }
  </code></pre>