Generics are really cool…
…
bummer – i thought i might have one of those "You’re our lucky 1,000,000th person who said that winner!" banner descend from Javascript heaven.
Anyway I had a hard time using them vs. code-generation of collection classes since code gen had the advantage of non-generic _names_. But I just found out we can do this:
public sealed class Role
{
private string _roleName;
public string RoleName
{
get { return _roleName; }
}
}
public sealed class RolesCollection : List<Role>
{
public Role this[string roleName]
{
get
{
foreach( Role r in this )
if( r.RoleName == roleName ) return r;
return null;
}
}
}
Now I can have my cake and eat it too. Yum.
-rory
Filed under: .Net Basics