Skip to content

Generics question

George George

Asked May 11, 2008, 12:36 AM EDT2 answers
Share
LinkedInX

Hello everyone,


I am migrated from C++ to C#. I am reading through about C++ template class and C# generics' differences,

http://msdn.microsoft.com/en-us/library/c6cyy67b(VS.80).aspx

3 questions,

1.

"At the implementation level, the primary difference is that C# generic type substitutions are performed at runtime and generic type information is thereby preserved for instantiated objects."

"preserved for instantiated objects" means?

2.

"In C#, a generic type parameter cannot itself be a generic, although constructed types can be used as generics. C++ does allow template parameters."

"constructed types" means?

3.

What means "C# disallows this; the only language constructs allowed are those that can be deduced from the constraints."?


thanks in advance,
George

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0

    1.

    "At the implementation level, the primary difference is that C# generic type substitutions are performed at runtime and generic type information is thereby preserved for instantiated objects."

    "preserved for instantiated objects" means?

    2.

    "In C#, a generic type parameter cannot itself be a generic, although constructed types can be used as generics. C++ does allow template parameters."

    "constructed types" means?

    3.

    What means "C# disallows this; the only language constructs allowed are those that can be deduced from the constraints."?


    thanks in advance,
    George

    1. The instantiated objects means the by reference objects, objects that the memory allocation is at the run time example class myClass = new class();
    2. Yes it can class<Type1<Type2>> my Class = new class<type1<type2>>();
    3. C# does not allow the type parameter to be used as the base class for the generic type
    0
  • 0

    Thanks Bechir,

     

    1.

    From your comments, I think "preserved for instantiated objects" means the information of the generics type parameter information is filled at runtime, and preserved at compile time?

    2.

    Your reply about (2) is great! But my confusion is about "constructed types can be used as generics", what does it mean?

    3.

    About your reply for my question  (3), I am confused. Where do you find base class related context/discussion in the paragraph where I have question? :-)

     

    regards,

    George

    0