Game Development Reference
In-Depth Information
Array.ForEach(
array,
delegate(int value)
{
sum
þ¼
value;
}
);
return sum;
}
This is called a closure. A delegate is created for each loop iteration, and uses the
same variable,
sum
. The variable
sum
can even go out of scope, but the anon-
ymous delegates will continue to hold a reference to it. It will become a private
variable only accessible to the functions that have
closed
it. Closures are used
heavily in functional programming languages.
C# 3.0
The release of C# 3.0 introduced more than just a few incremental changes. The
new features are extremely innovative and massively reduce the amount of boiler
plate code needed. The biggest change was LINQ system.
LINQ
LINQ stands for Language-Integrated Query. It's a little like SQL (SQL, Struc-
tured Query Language, is the language used to manipulate and retrieve data from
databases) for data structures. The best way to get a feel for it is to look at some
examples.
Monster
{
string _name;
int _currentLevel
¼
1;
int _currentExperience
¼
0;
int _nextLevelExperience
¼
1000;
public Monster(string name, int currentExperience)
{
_name
¼
name;
_currentExperience
¼
currentExperience;
}
public string Name()
Search WWH ::
Custom Search