score:12
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
Source: stackoverflow.com
Related Articles
- LINQ Source Code Available
- creating Linq to sqlite dbml from DbLinq source code
- Converting foreach loop to LINQ query breaks code
- source code for LINQ 101 samples
- c# Linq or code to extract groups from a single list of source data
- Converting LINQ (OrderBy/ThenBy) Code to CompareTo
- Converting SQL code with Row_Number() into LINQ C# code
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Syntax to execute code block inside Linq query?
- Converting a resource set into dictionary using linq
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Best open source LINQ provider
- Converting F# Quotations into LINQ Expressions
- Is there a good source that gives an overview of linq optimizations?
- Does this LINQ code perform multiple lookups on the original data?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- Converting Linq to XSLT
- Any better way for converting array to concurrent dictionary using linq or IEnumerable?
- LINQ WHERE method alters source collection
- Where can I view LINQ source code?
- Storing images with LINQ to SQL: Converting byte array or stream to Binary
- Suggestions for designing complex LINQ code
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Left outer join using LINQ -- understanding the code
- How to pass LinQ Expressions from F# to C# code
- How to reuse a linq expression for 'Where' when using multiple source tables
- How much database performance overhead when using LINQ?
- C# LINQ Distinct and ADO.NET EF
- Check all the children for XElement
- Several assignment into one Select
- Rewrite into a SortedList
- finding the highest element from an integer array which doesn't have duplicate
- Combining lists into one list which has cheapest ones among them
- Putting an order number on items in a linq query
- LinQ to generate statesOfCountry javascript array
- Summing and grouping values
- Linq sum on object w/o group
- how split the List of strings into another Lists if particular string matches condition using linq?
- Order by descending group by Max date, then order by single row in the group by date ascending using linq Method sintax
- Writing a sub query in LINQ with Top X
- Overriding or ignoring undeclared entities in C# using LINQ
- Groupby Transform into another group
- DataTable to List in C#
- Why does hard coding a function expression speed up query by four minutes?
- Short Circuit Linq for (Count > 1)
- LINQ DateTimeOffset expression could not be translated