admin管理员组

文章数量:1122832

I am having an issue with the Linq Distinct Method. I have a List of LocationID's

  • B A01A
  • B A01A
  • A A01A
  • A A01A
  • A A01A

As you can see, there are only two distinct values here. However, When they are passed through this code block here

var result = rootObject.OrderLines.Where(orderLine =>
orderLine.OrderAllocations
    .Where(y => y.StatusID != 250) 
    .Select(y => y.LocationID)  
    .Distinct() 
    .Count() == 1);

The count is 1 when in reality it should be 2.

However when I Modify the string with a .Concat() or .Reverse() method like below

var result = rootObject.OrderLines.Where(orderLine =>
orderLine.OrderAllocations
    .Where(y => y.StatusID != 250) 
    .Select(y => y.LocationID.Reverse())  
    .Distinct() 
    .Count() == 1);

the count is correct. not sure what is happening

本文标签: cDistinct method ony works when modifying stringStack Overflow