What is Closed constructed type and Open constructed type?

 Posted by Poster on 9/12/2010 | Category: C# Interview questions | Views: 4144 | Points: 40

Closed constructed type and open constructed type is term that is used while instantiated an object.

For exmaple
class myClassO<T>


Class MyClassC<int>


In above code class myClassO is the open constructed type as we can pass any type of parameter while instantiating the myClassO object.
myClassO<int> i = new myClassO<int>(20); // Correct

myClassO<string> i = new myClassO<strubg>('my string"); // Correct

You can notice that I can pass either integer or string in the myClassO insntiation as this is the generic class.

myClassC is the closed constructed type as I have specified the type of argument to be passed in the myClassC instantiation.

myClassC<int> i = new myClassC<int>(20); // Correct

myClassC<string> i = new myClassC<strubg>('my string"); // InCorrect

| Alert Moderator 

Comments or Responses

Login to post response