lundi 13 mars 2017

How to check if properties of two objects are equal

I have two objects using the ff. class:

public class Test {
    public string Name {get; set;}
    public List<Input> Inputs {get;set;}
    ......
    //some other properties I don't need to check
}

public class Input {
    public int VariableA {get;set;}
    public int VariableB {get;set;}
    public List<Sancti> Sancts {get;set;}
}

public class Sancti {
    public string Symbol {get;set;}
    public double Percentage {get;set;}
}

I want to check if two instance of Test has the same Inputs value. I've done this using a loop but I believe this is not the way to do this.

I've read some links: link1, link2 but they seem gibberish for me. Are there simpler ways to do this, like a one-liner something like:

test1.Inputs.IsTheSameAs(test2.Inputs)?

I was really hoping for a more readable method. Preferrably Linq.





Aucun commentaire:

Enregistrer un commentaire