Hi,
The Array.BinarySearch method doesn't accept the -eq expression. You have to uses the IComparer interface
https://learn.microsoft.com/en-us/dotnet/api/system.array.binarysearch?view=net-5.0#System_Array_BinarySearch_System_Array_System_Object_System_Collections_IComparer_
The code could be like this
Class ObjComparer : IComparer[System.Object] {
[System.Object]$x
[System.Object]$y
[int]Compare($x,$y) {
return [System.Collections.CaseInsensitiveComparer]::new().Compare($x.Name, $y)
}
}
$l1.BinarySearch("Ben", [ObjComparer]::new())
Best Regards,
Ian Xue
============================================
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.