c# - Must be a non abstract type with public parameterless constructor -


i read answers similar questions mine couldn't find explanation case. please, correct me, if i'm wrong :)

i have 3 classes - base abstract class, called emaildata, , 2 other classes derive base class. have not included 1 of inheriting classes , of members of other classes make example more obvious.

private abstract class emaildata     {         public emaildata(datarow emaildatarow)         {             vehicleowner = emaildatarow["owner"].tostring();         }          public string vehicleowner { { return vehicleowner; } }          private string vehicleowner;     }      private class deliveryemaildata : emaildata     {         public deliveryemaildata(datarow deliverydata)             : base(deliverydata)         {             ordernumber = deliverydata["ordernumber"].tostring();         }          public string ordernumber { { return ordernumber; } }          private string ordernumber;     } 

i have generic class, uses 1 of 2 classes derive base class emaildata, , looks this:

private class email<t> t : emaildata, new()     {         public email(datatable emaildatatable)         {             // number of rows.             int rowsnumber = emaildatatable.rows.count;              emailsdata = new t[rowsnumber];              (int = 0; < rowsnumber; i++)             {                 // store appropriate data in arrays.                 emailsdata[i] = (t)activator.createinstance(typeof(t), emaildatatable.rows[i]);             }              // email of recipient.             recipientemail = emaildatatable.rows[0]["delivery_email"].tostring();         }          public t[] emailsdata { { return emailsdata; } }         public string recipientemail { { return recipientemail; } }          private t[] emailsdata;         private string recipientemail;     } 

if decide make new instance of email class:

email<deliveryemaildata> email = new email<deliveryemaildata>(somedatatableobject); 

i following error:

'deliveryemaildata' must non-abstract type public parameterless constructor in order use parameter 't' 

when add parameterless constructor both base , derived classes, error no longer shows up. problem don't need parameterless constructor, 1 receives datatable object.

so, know wrong this?

you have constrained t t : new() meant must non-abstract i.e. must able create instance of type t , must have parameterless constructor. problem not in

public email(datatable emaildatatable){} 

which receives datatable in

public emaildata(datarow emaildatarow){} 

you can remove constraint new() solve problem.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -