score:12

Accepted answer

Can you still use C# 3.0 but not .NET 3.5? If so, keep the code as it is and use LINQBridge, which is LINQ to Objects implemented for .NET 2.0.

Otherwise, do this:

[DataObjectMethod(DataObjectMethodType.Select)]
public IEnumerable<OperatorField> FindByType(String type)
{
    List<OperatorField> list = new List<OperatorField>();
    foreach (OperatorField ce in OperatorFields)
    {
        if (ce.Type == type)
        {
            list.Add(ce);
        }
    }
    return list;
}

score:1

Something like this perhaps?

IList<OperatorField> col = new List<OperatorField>();
foreach (OperatorField f in this.OperatorFields)
{
    if (f.Type == type)
        col.Add(f);
}
return col;

score:1

[DataObjectMethod(DataObjectMethodType.Select)]
public IEnumerable<OperatorField> FindByType(String type)
{
    foreach (OperatorField ce in this.OperatorFields)
    {
        if (ce.Type == type)
            yield return ce;
    }
}

score:0

Think about what the statement is doing, it's iterating over each item in the OperatorFields property, checking the type and then adding the item to a list before returning the completed list.

So you've got

Create new list
For each item in OperatorFields
  if item.Type equals type
    add item to list

return list

Related Articles