I blogged recently about using public Collection
public class AddressCollection : Collection<Address> {
public AddressCollection() : base(new List<Address>()) { }
}
And I thought: why not to use generics to ensure that base class constructor is called? It works fine, I tested it:
Friday, May 30, 2008
A generic ListCollection<T> class
Thursday, May 01, 2008
C# block scoping rules for variables, anonymous methods and lambdas
I was reading Rick Strahl's blog post about "Variable Scoping in Anonymous Delegates in C#". I added a completely wrong comment there. That happens when studying too many languages at the same time. (My only excuse is that even Rick itself wasn't entirely right.)
JavaScript, Scala, and F# allow to hide outer variable by declaring another variable with the same name in a nested scope. C# does not allow to do that!
In C# lambdas and anonymous methods are treated as inline code placed into a nested block scope. It is consistent with the fact that they can access local variables from outer scope.
Behind the scenes compiler activities of creating actual delegate object and closure behavior are what they are: behind the scenes compiler activities. They should not and do not affect lexical rules.
And those lexical scoping rules for nested blocks, anoyimous methods, and lambdas are as followed: