0

i have to list and in to list i have list of string :

 public async Task<OperationResult<string>> SetAccess(AccessLevelDto accessLevels)
    {
            var access = await GetAccessLevels(accessLevels.RoleId);
    }

 private async Task<IEnumerable<string>> GetAccessLevels(Guid roleId)
    {
        return await AccessLevels.Where(x => x.RoleId == roleId).Select(x => x.Access).ToListAsync();
    }

one list : GetAccessLevels(accessLevels.RoleId) and second accessLevels.Access

i want to find with items exist in list A and not exist in list B then put then in the var mustremove .

how can i do this ????

mr coder
  • 199
  • 2
  • 14
  • 1
    Does this answer your question? [Use LINQ to get items in one List<>, that are not in another List<>](https://stackoverflow.com/questions/3944803/use-linq-to-get-items-in-one-list-that-are-not-in-another-list) – devlin carnate Apr 17 '20 at 16:23

1 Answers1

0

Use "Not Contains" LINQ expression:

var listA = new List<string> { "One", "Two", "Three" };
var listB = new List<string> { "One", "Three" };

var mustremove = listA.Where(x => !listB.Contains(x));

mustremove will contain one element: "Two"

Vasyl Chuy
  • 31
  • 3