 <p>It's pretty obvious here:</p> <pre><code>FileInfo[] fileinfo=null; // &lt;-- fileinfo is null for (int i = 0; i &lt; num; i++) { fileinfo[i] = new FileInfo(files[i]);//Exception at this line of code // ^--- fileinfo is still null! } </code></pre> <p>you are trying to use the indexer on a null reference to set a value. I think you want:</p> <pre><code>FileInfo[] fileinfo= new FileInfo[num]; for (int i = 0; i &lt; num; i++) { fileinfo[i] = new FileInfo(files[i]);//Exception at this line of code } </code></pre> <p>or just</p> <pre><code>FileInfo[] fileinfo = files.Select(f =&gt; new FileInfo(f)).ToArray(); </code></pre> <p><strong>EDIT</strong></p> <p>After reading your comments, it seems that you think that <code>FileInfo[] fileinfo=null;</code> will initialize an array of null values (which is true in some languages, but not C#). In fact, it creates an array variable that is <em>itself</em> a null value. To initialize an array, you use the syntax <code>FileInfo[] fileinfo=new FileInfo[size];</code> which <em>will</em> create an array of null values (more precisely, of the default value for <code>FileInfo</code>, which is <code>null</code> since it's a reference type). </p>