views:

26

answers:

1

I'm originally a C# developer (as a hobby), but as of late I have been digging into Ruby on Rails and really enjoying it. Right now I am building an application in C#, and I was wondering if there is any collection implementation for C# that could match (or "semi-match") the find_by method of ActiveRecord.

What I am essentially looking for is a list that would hold Rectangles:

class Rectangle
{
    public int Width { get; set; }
    public int Height { get; set; }
    public string Name { get; set; }
}

Where I could query this list and find all entries with Height = 10, Width = 20, or name = "Block". This was done with ActiveRecord by doing a call similar to Rectangle.find_by_name('Block'). The only way I can think of doing this in C# is to create my own list implementation and iterate through each item manually checking each item against the criteria. I fear I would be reinventing the wheel (and one of poorer quality).

I am not necessarily trying to match the naming convention find_by_..., but rather to have the functionality of the method.

Any input or suggestions is much appreciated.

+1  A: 

The "Linq methods", namely Where, that were added in .NET 3.5 are pretty close to what you're looking for.

myCollection.Where(r => r.Name == 'Block')
Matti Virkkunen
Ah! Thank you so much. This is exactly what I was looking for but I didn't quite know what to search for.
Benjamin Manns