It depends on your real requirements, but choosing more appropriate data structures could be one approach.
One example would be a Dictionary with a Tuple<int, int>
as the key, where the first item is the row index and the second item is the column index. "Search" would now be a lookup and O(1):
Dictionary<Tuple<int, int>, MyObject> MyObjects;
MyObject o;
if(MyObjects.TryGetValue(Tuple.Create(r, s), out o)
{
//found, do sth...
}
Adding a new object to the dictionary would look like this:
MyObjects.Add(Tuple.Create(o.rowIndex, o.colIndex), o);
If - for some reason - you would need to iterate all objects in another method, you can still do this using the Values
property of the dictionary:
foreach(var o in MyObjects.Values)
{
// do something for each of your objects.
}