new() keyword in the base declaration statement in C# -


this question has answer here:

i wonder below new() keyword. new() in base declaration statement along idisposable c : dbcontext , idisposedtracker.

but wonder new() expression. anonymous base class declaration?

but notice couple of arrow marked next new(). curly brackets owned public class repositorybase, not new().

what new() here?

namespace personrepository {     public class repositorybase<c> : idisposable c : dbcontext, idisposedtracker, new()     ->{         public repositorybase()         {             datacontext.database.createifnotexists();         }          private c _datacontext;          public virtual c datacontext         {                         {                 if (_datacontext == null || _datacontext.isdisposed)                 {                     _datacontext = new c();                     allowserialization = true;                     //disable proxycreationdisabled prevent "in order serialize parameter, add type known types collection operation using serviceknowntypeattribute" error                 }                  return _datacontext;             }         }          //partly omitted          public void save()         {             datacontext.savechanges();         }          public void dispose()         {             if (datacontext != null) datacontext.dispose();         }     }<-       } 

the new() costraint ...it means c has class , has empty constructor ...


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -