C # array of objects - conditional check

Sorry for the vague title!

I have a class with multiple member variables (system, zone, site, ...)

public sealed class Cello
{
    public String Company;
    public String Zone;
    public String System;
    public String Site;
    public String Facility;
    public String Process;
    //...
}

      

I have an array of objects of this class.

private Cello[]   m_cellos = null;
// ...

      

I need to know if the array contains objects with the same site, but different systems, zones or companies, as such a situation would be illegal. I have different checks, but they are all similar.

The Array class has a number of functions that look promising, but I'm not very good at defining "key selector" functions and the like.

Any suggestions or pointers are greatly appreciated.

--- Alistair.

+2


a source to share


2 answers


bool illegalCellos = m_cellos
    .Any(c => m_cello
        .Any(nc => nc.Site == c.Site && 
            (nc.Zone != c.Zone || nc.System != c.System || nc.Company != c.Company)));

      



+5


a source


Instead of putting things into an array, perhaps you could look into using DataTable.

Then you can search with simple SQL statements.



This is useful if you have a lot of records.

0


a source







All Articles