c# - Error 7, argument 1: cannot convert from ' ' to ' ' -


i coming across error have not seen before. hoping 1 can help.

here code:

public class myt {     public int id { get; set; }     public myt set(string line)     {         int x = 0;          this.id = convert.toint32(line);          return this;     } }  public class mylist<t> : list<t> t : myt, new() {     internal t add(t n)     {         read();         add(n);         return n;     }     internal mylist<t> read()     {         clear();         streamreader sr = new streamreader(@"../../files/" + gettype().name + ".txt");         while (!sr.endofstream)             add(new t().set(sr.readline())); //<----here error!         sr.close();         return this;     } }  public class customer : myt {     public int id { get; set; }     public string firstname { get; set; }     public string lastname { get; set; } }  public class item : myt {     public int id { get; set; }     public string category { get; set; }     public string name { get; set; }     public double price { get; set; } }  public class myclass {     mylist<customer> customers = new mylist<customer>();     mylist<item> items = new mylist<item>(); } 

on line says, "add(new t().set(sr.readline()));" "error 7, argument 1: cannot convert 'simple_reservation_system.myt' 't'". can please me fix this.

your type mylist can contain elements of type "t" (specified when list declared). element trying add of type "myt", cannot downcasted "t".

consider case in mylist declared subtype of myt, myothert. not possible cast myt myothert.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -