Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Comparable object

How to create comparable objcet via -eq, like .NET object. For example:

class test{
    $a
    $b
    test($a,$b){
        $this.a=$a
        $this.b=$b
    }
}
$obj = [test]::new(4, 5) 
$obj -eq [test]::new(4, 5)
# False

$pt = [System.Drawing.Point]::new(4, 5)
$pt -eq [System.Drawing.Point]::new(4, 5)
# True
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Per the documentation:

To create comparable classes, you need to implement System.IEquatable<T> in your class.

class MyFileInfoSet : System.IEquatable[Object] {
    [String]$File
    [Int64]$Size

    [bool] Equals([Object] $obj) {
        return ($this.File -eq $obj.File) -and ($this.Size -eq $obj.Size)
    }
}
$a = [MyFileInfoSet]@{File = "C:\Windows\explorer.exe"; Size = 4651032}
$b = [MyFileInfoSet]@{File = "C:\Windows\explorer.exe"; Size = 4651032}
$a -eq $b
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!