I am trying to understand the limitations for type type parameters in C #. What is the purpose of the where T : new() constraint? Why do you need to insist that the type argument has an open constructor with no parameters?
Edit: I have to miss something. The highest rating says that to create a typical type, an open parallel-free constructor is needed. If so, why is this code compiled and run?
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) {
Edit: In his comment, gabe reminded me that if I did not define a constructor, the compiler would provide a parameter without parameters by default. So, the Foo class in my example actually has an open constructor with no parameters.
raven source share