Skip to content

Commit

Permalink
AV1250: Updated example (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman authored and dennisdoomen committed May 23, 2018
1 parent 242bc77 commit 9d3563f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions _pages/1200_MiscellaneousDesignGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Instead of casting to and from the object type in generic types or methods, use

Consider the following code snippet

public IEnumerable GetGoldMemberCustomers()
public IEnumerable<GoldMember> GetGoldMemberCustomers()
{
const decimal GoldMemberThresholdInEuro = 1_000_000;
Expand All @@ -97,7 +97,7 @@ Consider the following code snippet
return query;
}

Since LINQ queries use deferred execution, returning `query` will actually return the expression tree representing the above query. Each time the caller evaluates this result using a `foreach` cycle or similar, the entire query is re-executed resulting in new instances of `GoldMember` every time. Consequently, you cannot use the `==` operator to compare multiple `GoldMember` instances. Instead, always explicitly evaluate the result of a LINQ query using `ToList()`, `ToArray()` or similar methods.
Since LINQ queries use deferred execution, returning `query` will actually return the expression tree representing the above query. Each time the caller evaluates this result using a `foreach` loop or similar, the entire query is re-executed resulting in new instances of `GoldMember` every time. Consequently, you cannot use the `==` operator to compare multiple `GoldMember` instances. Instead, always explicitly evaluate the result of a LINQ query using `ToList()`, `ToArray()` or similar methods.

### <a name="av1251"></a> Do not use `this` and `base` prefixes unless it is required (AV1251) ![](/assets/images/1.png)

Expand Down

0 comments on commit 9d3563f

Please sign in to comment.