Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8314527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:50:55+00:00 2026-06-08T20:50:55+00:00

I have two List<FileInfo> and I want to return the common FileItem between them.

  • 0

I have two List<FileInfo> and I want to return the common FileItem between them.

List<FileInfo> outputList = new List<FileInfo>();
outputList = list1.Intersect(list2).ToList();

However, I’m getting back an empty List.

Both the lists contain FileInfo‘s found by

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);
IEnumerable<System.IO.FileInfo> fileList = 
dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);

And filtered by queries.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:50:56+00:00Added an answer on June 8, 2026 at 8:50 pm

    I suspect that FileInfo doesn’t override Equals/GetHashCode, so two distinct objects will be unequal even if they refer to the same file. Three options:

    • Convert the lists to paths if you don’t need them as FileInfo
    • Create an IEqualityComparer<FileInfo> and pass that to Intersect
    • Implement IntersectBy in the same style as DistinctBy in MoreLINQ and propose it as a patch to the project 🙂 (I thought we already had it, but apparently not…)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two List<int> instances. Now I want to combine them into a third
I have two list of Parameters, where you can move them between the two
I have these two collections: List<string> files = Directory.GetFiles(FilePath).ToList().Select(file => new FileInfo(file).Name).ToList(); string[] dirs
i have two list want to compare and then filter it. so if list1
I have two list in a python list1=['12aa','2a','c2'] list2=['2ac','c2a','1ac'] First- Finding combinations of each
Ho I have two list view on a frame layout. I want one overlay
i have two lists: List<comparerobj> list_c = new List<comparerobj>(); List<comparerobj> list_b = new List<comparerobj>();
I have two List of array string. I want to be able to create
I have two list list1 = [(100, A, 22), (200,B, 33), (300, C, 44)]
I have two list like this: list1 = [{'id':1, 'name':'foo', 'age':20}, {'id':2, 'name':'foo', 'age':20}]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.