Aamec Aamec
Aamec Aamec

Reputation: 1

Linq Query For matching at least Five Numbers From the Given List

i have a list - finalbetfile2

The class is,

 class finalbetfile
    {
        public int[] BetInfo{ get; set; }
        public string TransID { get; set; }
        public string BetAmount { get; set; }
        public string TransDateTime { get; set; }

    }

The BetInfo column has six integers values, I want to match the Betinfo with my rank3of1(Result) with any order,the code is given below

 var rank3of1 = new int[] { intball1, intball2, intball3, intball4, intball5, intball6 };
 var filteredProjects8 = finalbetfile2.Where(p => rank3of1.All(tag => p.BetInfo.Contains(tag)));

It works fine but matching against all 6 numbers instead of at least 5.

Upvotes: 0

Views: 94

Answers (2)

Gert Arnold
Gert Arnold

Reputation: 109185

Use Intersect:

var filteredProjects8 = finalbetfile2
    .Where(p => rank3of1.Intersect(p.BetInfo).Count() >= 5);

Upvotes: 2

Sayse
Sayse

Reputation: 43320

You can use Count instead of All and check if this count is greater than or equal to 5

finalbetfile2.Where(p => rank3of1.Count(tag => p.BetInfo.Contains(tag)) >= 5);

Upvotes: 3

Related Questions