---
title: "FileInfo - Select one File out of one FileInfo[]"  
description: "FileInfo - Select one File out of one FileInfo[]"  
author: "Anonymous User"  
published: 2014-02-04  
updated: 2014-02-04  
canonical: https://www.mindstick.com/forum/1953/fileinfo-select-one-file-out-of-one-fileinfo  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# FileInfo - Select one File out of one FileInfo[]

I have two FileInfo[] [Array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net)'s and i want [compare](https://www.mindstick.com/forum/2036/propertyinfo-getvalue-unable-to-compare-datetimes) the [Files](https://www.mindstick.com/articles/23302/the-importance-and-advantage-of-keeping-your-important-files-on-the-cloud) with identical Names about their [File Size](https://www.mindstick.com/forum/12663/how-to-set-file-size-in-grid-view) and Last [Modified Date](https://www.mindstick.com/forum/33759/how-to-get-last-modified-date-using-alasset-class-in-ios). But how can i [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) a File out of a FileInfo[] with a specific Name?

My [Code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) doesnt work, because i cant use FileInfo.Select to get a new FileInfo out. Any clues?

```
        foreach (FileInfo origFile in fiArrOri6)        {            FileInfo destFile = fiArrNew6.Select(file => file.Name == origFile.Name);            if (origFile.Length != destFile.Length || origFile.LastWriteTime != destFile.LastWriteTime)            {                //do sth.            }        }
```

Thanks for any help :)

Any other charming solution for this [Problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) would be great. btw. #2 : does someone has good [learning](https://www.mindstick.com/articles/126221/instructional-design-for-elearning-why-it-is-so-important) material for FileInfo?

## Replies

### Reply by Pravesh Singh

Hi Jayprakash,

You could use the FirstOrDefault that takes a filter

FileInfo destFile = fiArrNew6.FirstOrDefault([file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) => file.Name == origFile.Name);

Or, if you don't want the default, you can use the equivalent First that takes a filter

FileInfo destFile = fiArrNew6.First(file => file.Name == origFile.Name);


---

Original Source: https://www.mindstick.com/forum/1953/fileinfo-select-one-file-out-of-one-fileinfo

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
