Cannot create an instance of the variable type ‘Item’ because it does not have the new() constraint

You can’t initialize Generic type object unless you mark it as implementing default constructor using new keyword:

public void CountTestHelper<Item>() where Item : IHasRect, new()
 {
    Rectangle rectangle = new Rectangle(0, 0, 100, 100); 
    SomeClass<Item> target = new SomeClass<Item>(rectangle);            
    Point p = new Point(10,10);
    Item i = new Item();    // constructor has to be parameterless!
    ...
 }

On the other hand, if you’re trying to initialize an Item type object defined somewhere else in the application try using the namespace before it:

MyAppNamespace.Item i = new MyAppNamespace.Item(p, 10);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)