C# Generics.

  • Thread starter Thread starter Eddie
  • Start date Start date
E

Eddie

Hi,

I've recently read the articles on generics in the .net
framework (the next version) and just wanted to check a
few points..

As I understand, generic class instances while being
strongly typed checked at compile time, are only created
at runtime?? Is this correct??

Secondly, can you inherit from a typed generic class??
i.e.
public class MySortedList:GenericSortedList<int32>
{
}

ANy feedback would be sweet..

thanks..

Eddie
 
Hi Eddie

This is from memory of a session at an MS conference, so it might not be
100% correct.

Generics will be type checked at compile time, and a class created for each
class type and value type that uses them. For instance, if you have multiple
lists containing ints, the internally only one set of code will be required
to handle the lot. The generics in Rotor do not do this.

I'm not sure that the issue of inheritance was discussed. I just assumed you
can inherit. Take a look at the Rotor generics - they should tell you.

Regards

Ron
 
We're planning to introduce generics starting with Visual Studio "Whidbey,"
which we won't be talking a lot about until the Professional Developers
Conference at the end of this month. If you want more information, check on
MSDN the week of October 28th.

Thanks,
John

Director, Product Management
..NET Framework
Microsoft
 
--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
Eddie said:
Hi,

I've recently read the articles on generics in the .net
framework (the next version) and just wanted to check a
few points..

As I understand, generic class instances while being
strongly typed checked at compile time, are only created
at runtime?? Is this correct??

The IL to implement a specific use of a generic class (ie List<int>) is
created at JIT time, unless it's already been created. Each value type needs
a separate set of IL, but reference types can share their IL.
Secondly, can you inherit from a typed generic class??
i.e.
public class MySortedList:GenericSortedList<int32>
{
}

Yes.
 
Back
Top