Hi @MyLadys-4900,
I also have a hashset<int> addOnOptions that has a number of svcIds, say 11 and 17
My objective is to end up with:
5 / serviceA / 10.00
19 / serviceB / 19.25
2 / serviceE / 9.00
var theSelectedAddOns = addOnOptions.ToList().Where(x => new[] {services.ToList()}.Contains(x));
From your description, I assume you want to filter the service array based on the addOnOptions value. If that is the case, the LINQ query statement should like this:
var services = new ServiceGrid [] {
new ServiceGrid() { svcId = 5, svcName = "serviceA", svcBillingRate = 10.00M },
new ServiceGrid() { svcId = 19, svcName = "serviceB", svcBillingRate = 19.25M },
new ServiceGrid() { svcId = 11, svcName = "serviceC", svcBillingRate = 24.00M },
new ServiceGrid() { svcId = 17, svcName = "serviceD", svcBillingRate = 4.5M },
new ServiceGrid() { svcId = 2, svcName = "serviceE", svcBillingRate = 9.00M }
};
var addOnOptions = new HashSet<int> { 11, 17 };
//Find service from the array which its svcId not in the addOnOptions.
var result = services.ToList().Where(c => !addOnOptions.ToList().Contains(c.svcId)).ToList();
//Find service from the array which its ID in the options.
var result2 = services.ToList().Where(c => addOnOptions.ToList().Contains(c.svcId)).ToList();
The result like this:
------
If the answer doesn’t solve your issue, please provide more details of error that will help us track down what’s happening.
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
Dillion