Neil Reed

XNA Turn Based Game Blog

Delegation and foreach loops

4 Response to Delegation and foreach loops

15 January 2010 at 12:19

You can also use LINQ which is very efficient:
using System.Linq;



GoldenEgg = (from e in Basket
where e.isGolden
select e).FirstOrDefault();

The benefits are even more obvious with more complicated queries. You can use LINQ to query collections of objects, xml, and even databases.

18 January 2010 at 16:45

Bryan, Linq is cool for stuff like that.

However from doing further reading its going to be pointless for the game due to garbage collection :(

11 June 2010 at 22:41

or, Linq with Lambda

GoldenEgg = Basket.Find(e => e.isGolden);

15 June 2010 at 15:20

I think we have proven there are many different ways to achieve the same outcome :)