lunes, 27 de agosto de 2012

Interfaces de los contenedores IQueryable, ICollection, IList e IDictionary

Para autoevaluar el proyecto en el que trabajo, audité la solución para comprobar la cobertura de código de las pruebas unitarias, warnings.

Entre los warnings que me devolvia VisualStudio 2010, me llamo la atención que me levantaba el riesgo de utilizar List y lo cambiase por ICollection.

Diferencias había entre estos tipos de colecciones:

All of these interfaces inherit from IEnumerable, which you should make sure you understand. That interface basically lets you use the class in a foreach statement (in C#).
  • ICollection is the most basic of the interfaces you listed. It's an enumerable interface that supports a Count and that's about it.
  • IList is everything that ICollection is, but it also supports adding and removing items, retrieving items by index, etc. It's the most commonly-used interface for "lists of objects", which is vague I know.
  • IQueryable is an enumerable interface that supports LINQ. You can always create an IQueryable from an IList and use LINQ to Objects, but you also find IQueryable used for deferred execution of SQL statements in LINQ to SQL and LINQ to Entities.
  • IDictionary is a different animal in the sense that it is a mapping of unique keys to values. It is also enumerable in that you can enumerate the key/value pairs, but otherwise it serves a different purpose than the others you listed.
Comprendí que en el flujo operativo de nuestra lógica trabajábamos con una colección que no se modificada.

Thanks!!
 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Online Project management