Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Лаба №1 / books / csharp_ebook.pdf
Скачиваний:
77
Добавлен:
03.03.2016
Размер:
3.69 Mб
Скачать

Programmers Heaven: C# School

could “escape” into that, so when it comes to runtime they are not really local variables anymore. Thinking of the anonymous method as if it were capturing the locals that it uses in its enclosing method probably provides a more helpful way of thinking about what is going on here, though. This process is known as taking a closure.

Author's Note: If this section on more advanced uses of anonymous methods has made you scratch your head somewhat, you’re probably not alone. Most programmers are used to the idea of passing data around, but fewer are as used to or comfortable with the idea of passing references to chunks of code around. This is sometimes referred to as higher order programming, and is commonly done in the functional programming paradigm. Concepts such as closures and parametric polymorphism have also been popular in functional programming for some time – it’s interesting to see them continue to break into more mainstream languages.

Final thoughts on C# 2.0

This chapter hasn’t covered every new feature in C# 2.0, but it has explored four of the most major additions that will enable you to develop more robust and efficient solutions, usually with less effort. I hope this chapter has not just explained the features, but also given you a feel for where they can help and what kinds of problems they are applicable to. Remember that the newest toy in the box isn’t always the best one to help solve your problem – but don’t be afraid to try out the new toys either!

337

Соседние файлы в папке books