Searching for data in a table How can I optimize this code to increase the performance of searching data?

public class TableRowInfo : IEquatable&lt;GridRowInfo&gt;
{
    #region Ctor

    public TableRowInfo(int rowIndex, object rowData, NodeEntry nodeEntry, bool isNewRow = false)
    {
        this.RowData = rowData;
        this.NodeEntry = nodeEntry;
        this.RowIndex = rowIndex;
        this.IsNewRow = isNewRow;
    }


    public TableRowInfo(int rowIndex, bool isNewRow)
    {
        this.RowData = null;
        this.NodeEntry = null;
        this.RowIndex = rowIndex;
        this.IsNewRow = isNewRow;
    }

    #endregion

    #region Properties


    public object RowData { get; private set; }


    public bool IsDataRow
    {
        get { return RowData != null; }
    }


    public bool IsNewRow
    {
        get;
        set;
    }


    public int RowIndex { get; internal set; }


    internal NodeEntry NodeEntry { get; private set; }

    #endregion

    public override int GetHashCode()
    {
        int rowDataHashCode = this.RowData == null ? 0 : this.RowData.GetHashCode();
        return rowDataHashCode ^ this.RowIndex;
    }

    #region IEquatable&lt;TableRowInfo&gt; Members

    public bool Equals(GridRowInfo other)
    {
        if (Object.ReferenceEquals(other, null)) return false;

        if (Object.ReferenceEquals(this, other)) return true;

        if (!this.IsDataRow == other.IsDataRow)
            return false;
        else if (this.IsDataRow)
            return this.RowData == other.RowData;
        else
            return this.RowIndex == other.RowIndex;
    }

    #endregion
}

public class TableSelectedRowsCollection : List&lt;TableRowInfo&gt;
{
    #region Ctor

    public TableSelectedRowsCollection()
    {
    }

    #endregion

    #region IList Members

    public bool Contains(TableRowInfo rowInfo)
    {
        if (rowInfo.IsNewRow)
            return Find(rowInfo.RowIndex) != null;
        else
            return Find(rowInfo.NodeEntry) != null;
    }

    public bool Contains(int rowIndex)
    {
        return Find(rowIndex) != null;
    }

    public bool Contains(object rowData)
    {
        return Find(rowData) != null;
    }

    public bool Contains(NodeEntry nodeEntry)
    {
        return Find(nodeEntry) != null;
    }

    #endregion

    #region Helper Methods

    internal TableRowInfo Find(NodeEntry nodeEntry)
    {
        if (nodeEntry != null &amp;&amp; this.Count &gt; 0)
        {
            return this.FirstOrDefault(rowInfo =&gt; rowInfo.NodeEntry == nodeEntry);
        }
        return null;
    }

    internal TableRowInfo Find(int rowIndex)
    {
        if (rowIndex &gt; 0 &amp;&amp; this.Count &gt; 0)
        {
            return this.FirstOrDefault(rowInfo =&gt; rowInfo.RowIndex == rowIndex);
        }
        return null;
    }

    internal TableRowInfo Find(object rowData)
    {
        if (rowData != null &amp;&amp; this.Count &gt; 0)
        {
            return this.FirstOrDefault(rowInfo =&gt; rowInfo.RowData == rowData);
        }
        return null;
    }

    internal TableRowInfo Find(TableRowInfo rowInfo)
    {
        if (rowInfo != null &amp;&amp; this.Count &gt; 0)
        {
            return this.FirstOrDefault(item =&gt; item.NodeEntry == rowInfo.NodeEntry);
        }
        return null;
    }

    internal List&lt;int&gt; GetRowIndexes()
    {
        var rowIndexes = new List&lt;int&gt;();
        if (this.Count &gt; 0)
        {
            this.ForEach(rowInfo =&gt; rowIndexes.Add(rowInfo.RowIndex));
        }
        return rowIndexes;
    }

    #endregion
}
For faster searching and since you're searching by different properties, one way would be a different dictionary for each property you want to search for. The indexing property is the key and the value can be the tablerowinfo object or if indexes may be duplicated a list of tablerowinfoinfo objects.

Dictionary&lt;NodeEntry, TableRowInfo&gt; nodeEntryIndex;
Dictionary&lt;int, TableRowInfo&gt; rowNumberIndex;
Dictionary&lt;object, TableRowInfo&gt; rowDataIndex;


Assuming you've implemented Add and Remove methods, simply add/remove the appropriate entries to the dictionaries, in those methods.

The Find method would look something like this:

internal TableRowInfo Find(NodeEntry nodeEntry)
{
    if (nodeEntryIndex.ContainsKey(nodeEntry))
    {
        return nodeEntryIndex[nodeEntry];
    }
    return null;
}


One suggestion.  When you inherit from a List like this, you expose all the members you've inherited from the list, outside the class.  If you're going to provide your own version for all of them that's fine.  However if you're only going to implement a subset of them then you might want to consider not inheriting but having a List as a private property to store the collection.  This gives you much more flexibility in choosing what gets exposed outside the class.

Another suggestion.  Instead of using object as the rowData type, the DataRow Class would probably be better suited for that.  This increase the robustness of your class.