luke,
Generics are a great way to get general functionality while exposing
specific types.
You have already mentioned the example of collections, for example.
With interfaces and generics, they are a way of specifying the specific
type to use for the contract that makes up the interface.
For example, you know that the IEnumerator interface is going to iterate
through a list/collection/whatever. In order to support all types, it just
returns an object, which you then have to cast. This isn't type safe, and
an erroneous cast will be caught at run-time, not compile time.
With IEnumerator<T>, you don't have to cast, because the Current
property returns T. If you try to misassign this to another variable, you
catch it at compile time.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"luke" <lu**@hotmail.com> wrote in message
news:dr**********@sunce.iskon.hr...
Are they?
I mean, you could always downcast them for particular use, but then the
system would be well designed with intefaces instead of generics, and for
other uses I don't see any sense (collections excluded). Why do I need to
hold something of type 'object'? For what concrete usage? I am confused
with interfaces and generics... Please someone explain to me.