0

I got two .csv files as shown below:

1st file:

"id"
4
1
3

2nd file:

"id"
1
2
3
4
5

I would like to check whether in first file there are all values from second file (no matter in which row they are). In my example in 1st file 2 and 5 values missing comparing to 2nd file so i would like to output somehow those values. How can i do that?

6

1 Answer 1

2

So you know how to read them and don't know how to find out which are missing? You can use Enumerable.Except

IEnumerable<string> firstFileIds = GetFileIds(...);
IEnumerable<string> secondFileIds = GetFileIds(...);
IEnumerable<string> missingInFirst = secondFileIds.Except(firstFileIds);

Console.Write($"Missing in 1st file: {string.Join(",", missingInFirst)}");
Sign up to request clarification or add additional context in comments.

3 Comments

Error: cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'char'
Just additional question, do you know how to list duplicates out first list?
@Henry: var dups=firstFileIds.GroupBy(id=>id).Where(g=>g.Count()>1).Select(g=>g.Key);. Instead of g.Count()>1 you can also use g.Skip(1).Any() since that could be more efficient

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.