0

I am trying to select only the matching fields from one list i.e. List<TEntity> on the basis of fields in another list i.e. List<string>.

var list = new List<TEntity>();
// Code for populating the list. Let's say this holds list data like: Id, Name, Type, Address, Department
var columns = commaSeparatedcolumns.Split(',').ToList();//commaSeparatedcolumns: "Id, Address, Department"
// Need to return list with only matched fields. In this case those matched fields will be: Id, Address, Department
// Tried following approach but had no success:
list.Where(x => columns.Any(y => y.Equals(x)));

Can someone please provide any clue? Thanks for the help in advance.

James Z
  • 12,209
  • 10
  • 24
  • 44
Rajan Patekar
  • 105
  • 1
  • 7

0 Answers0