background preloader

C# Specific Topics

Facebook Twitter

C# Corner. C# - Two-way data binding objects. LINQ. Lambda Expressions. Anonymous Methods (C# Programming Guide) In versions of C# before 2.0, the only way to declare a delegate was to use named methods.

Anonymous Methods (C# Programming Guide)

C# 2.0 introduced anonymous methods and in C# 3.0 and later, lambda expressions supersede anonymous methods as the preferred way to write inline code. However, the information about anonymous methods in this topic also applies to lambda expressions. There is one case in which an anonymous method provides functionality not found in lambda expressions. Anonymous methods enable you to omit the parameter list. This means that an anonymous method can be converted to delegates with a variety of signatures. The "yield return" Statement. When you use the yield keyword in a statement, you indicate that the method, operator, or get accessor in which it appears is an iterator.

The "yield return" Statement

Using yield to define an iterator removes the need for an explicit extra class (the class that holds the state for an enumeration, see IEnumerator<T> for an example) when you implement the IEnumerable and IEnumerator pattern for a custom collection type. The following example shows the two forms of the yield statement.