Public class CompareItems
{
Public string type {get; set; }
Public int item1 { get; set; }
Public int item2 { get; set; }
}
Public List< CompareItems> compareJobList = new List< CompareItems>();
I can populate this okay, but I now have a requirement to check that the list does not accept duplicate values. I know this could be done on normal list by using the contains function.
However can it be done on this type of a list?
So I would need to check all 3 values don't exist?
C#ASP.NET.NET Programming
Last Comment
Göran Andersson
8/22/2022 - Mon
dj_alik
If you're using .NET 3.5 or later, LINQ is the answer to this one:
compareJobList .Where(t => t.item1 == 3);
dj_alik
if less .net 3.5
compareJobList .Exists(t => t.item1 == 3&& t.item2=1)
or
compareJobList .FindAll(t => t.item1 == 3&& t.item2=1)
kaufmed
If you're using .NET 3.5 or later, LINQ is the answer to this one:
compareJobList .Where(t => t.item1 == 3);
I'd suggest Any instead of Where.
using System.Linq;...bool exists = compareJobList .Any(t => t.item1 == 3);
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
compareJobList .Where(t => t.item1 == 3);