1) I read some (general) code snippet and saw some places that used IList<T> and some used IEnumerable. What is the pros to use the first over the latter?
2) is and as in c#.
I understand is does type check and as does casting.
But what is exactly casting? forcing data to some sized object? when is and as differ?
A
IList[<T>]represents something that:An
IEnumerable, on the other hand, can only be iterated. Not all things that can be iterated are lists. For example:that ^^^ is an infinite sequence. It has no length, cannot be mutated, cannot be accessed by index… however, it can be iterated:
isperforms a type check that returnstrue/false… i.e. isobjanIList? yes or no.asperforms a “try to do this” type-check; it returnsnullif it fails, or a typed reference (etc) if it is successful. Basically, it is an efficiency thing:is less efficient than:
they also behave differently ifobjis null;isthrows an exception;asreturnsnull.