2

Sorry about the vague title!

I have an class with a number of 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 whether the array contains objects with the same site but different systems, zones or companies since such a situation would be illegal. I have various other checks to make but they are all along similar lines.

The Array class has a number of functions that look promising but I am not very up on defining 'key selector' functions and things like that.

Any suggestions or pointers would be greatly appreciated.

--- Alistair.

0

2 Answers 2

5
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)));
Sign up to request clarification or add additional context in comments.

1 Comment

@fishdump Hey..If Yuriy's sweet piece of code look like Greek then you might need to read up on Linq... including System.linq will expose most of these Array extension methods. If you already know about linq..I'll shut up now :) (it took me a week to figure out what exactly the gods were doing the first time I saw this syntax)
0

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

You can then search through it with simple SQL statements.

This is useful if you have a LOT of entries.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.