title: How to convert type int[] to int?[]
body: <p>I'm using a linq query to output an int array. But I need to pass this into a method that only accepts int?[]. </p>
  
  <p>So after searching on ways to convert int[] to int?[] I found something that seemed might work <a href="https://stackoverflow.com/a/28611320/1814739">here</a></p>
  
  <p>The following code is a simplified example that shows what is working and not working. </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Web;
  using System.Linq;
  
  namespace ConsoleApp
  {
      class Program
      {
          static void Main(string[] args)
          {
              // working...
              int[] vids1 = new[] { "", "1", "2", "3" }
                  .Where(x =&gt; !String.IsNullOrWhiteSpace(x))
                  .Select(x =&gt; Convert.ToInt32(x))
                  .ToArray();
  
              foreach(int i in vids1) 
              {
                  System.Diagnostics.Debug.WriteLine(i.ToString());
              }
  
              // not working...
              int?[] vids2 = new[] { "", "1", "2", "3" }
                  .Where(x =&gt; !String.IsNullOrWhiteSpace(x))
                  .Select(x =&gt; Convert.ToInt32(x))
                  .ToArrayOrNull();
          }
      }
  
      public static class IEnumerableExtensions
      {
          public static T?[] ToArrayOrNull&lt;T&gt;(this IEnumerable&lt;T&gt; seq)
          {
              var result = seq.ToArray();
  
              if (result.Length == 0)
                  return null;
  
              return result;
          }
      }
  }
  </code></pre>
  
  <p>I've played around with this extension method trying to get it to pass back int?[] type, but no luck as of yet. </p>
  
  <p>How can I get my IEnumerable extension <code>ToArrayOrNull</code> to pass back nullable types?</p>