Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
I know that C# generic class CAN'T take as a parameter
1. static class
C#
public static class StaticClass
{...}

...
GenericClass<StaticClass> obj= new GenericClass<StaticClass>();
...


2. pointer( in unsafe mode )
C#
...
GenericClass<int*> obj = new GenericClass<int*>();
...


What type else generic class parameter can't be?
Posted
Comments
thursunamy 15-May-14 9:58am    
Hi,

Actually it is related to your Generic Class Definition. It changes according to your definition. You can check http://msdn.microsoft.com/en-us/library/d5x73970.aspx
kDiana 16-May-14 2:24am    
Question is not related to Generic class parameter constraints.
Sergey Alexandrovich Kryukov 15-May-14 17:37pm    
Why not reading standard MSDN documentation?
—SA
kDiana 16-May-14 1:25am    
Sergey Alexandrovich, I've looked through whole c# documentation, googled a lot but can't found anything proper. If you could provide my question answer in MSDN I'd be very thankful to you.
Vedat Ozan Oner 16-May-14 2:40am    
actually that is an interesting question, but I try to understand the motivation behind it. why do you ask such a question about what can't be done? you use a language to do something. not 'not to do' something. yes, you can find 'to do' set by negating 'not to do' list, but you can ask 'to do' set directly :) the next question after that question would be 'why', which makes more sense in terms of understanding the background of the design. for example why not to use a static type parameter with a generic class. this may lead to another good talk.

1 solution

Finally, I found it!!!
It is dynamic class.
Dynamic class can't be parameter of Generic class.

When talking about dynamic class, I mean this =>

C#
/* Load in the assembly. */
 moduleAssembly = Assembly.LoadFile(fileName);

  /* Get the types of classes that are in this assembly. */
  Type type = moduleAssembly.GetTypes();

/* Create a new instance */
Activator.CreateInstance(type);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900