c# - on DLL file


i beginner programmer, learning c#. keep getting stack overflow error on .dll when link main .cs in visual studio , start debugging. code .dll below:

// begin namespace libemployee1 namespace libemployee1 {  /****************************************************************/ /* 1. class employee                                            */  /****************************************************************/  public class employee {  private const double fica_rate      = 0.07; private const double fed_tax_rate   = 0.22; private const double state_tax_rate = 0.05;  private int    id; private string lastname,firstname; private date   hiredate; private double rate; private double hours;  public employee() // default constructor {   this.id        = 0;   this.lastname  = "";     this.firstname = "";   this.hiredate  = new date();   this.rate      = 0.0;   this.hours     = 0.0; }  public employee(int idvalue, string lastnamevalue, // initializing constructor                 string firstnamevalue, date hiredatevalue,                  double ratevalue, double hoursvalue) {   this.id        = idvalue;   this.lastname  = lastnamevalue;     this.firstname = firstnamevalue;   this.hiredate  =  new date(hiredatevalue);   this.rate      = ratevalue;   this.hours     = hoursvalue; }  public employee(int idvalue, string lastnamevalue, // initializing constructor                 string firstnamevalue, int hireyearvalue,                 int hiremonthvalue, int hiredayvalue,                   double ratevalue, double hoursvalue) {   this.id        = idvalue;   this.lastname  = lastnamevalue;     this.firstname = firstnamevalue;   this.hiredate  = new date(hireyearvalue,hiremonthvalue,hiredayvalue);   this.rate      = ratevalue;   this.hours     = hoursvalue; }   public employee(int idvalue, string lastnamevalue, // initializing constructor                 string firstnamevalue, string hiredatestring,                  double ratevalue, double hoursvalue) {   this.id        = idvalue;   this.lastname  = lastnamevalue;     this.firstname = firstnamevalue;   this.hiredate  = date.parse(hiredatestring);   this.rate      = ratevalue;   this.hours     = hoursvalue; }  public employee(employee sourceemployee) // copy constructor {   this.hiredate = new date();   this.copy(sourceemployee); }   public int id   // define read/write id property {     {     return this.id;   }   set   {     if ((value >= 1) && (value <= 9999))       this.id = value;     else       processerror(string.format("{0} can not assigned id property\n\nabort?", value));   } }  public string lastname  // define read/write lastname property {     {     return this.lastname;   }   set   {     this.lastname = value.trim();   } }  public string firstname  // define read/write firstname property {     {     return this.firstname;   }   set   {     this.firstname = value.trim();   } }  public date hiredate  // define read/write hiredate property {     {     return this.hiredate;   }   set   {     this.hiredate.copy(value);   } }  public double rate // define read/write rate property {     {     return this.rate;   }   set   {     if ((value >= 0) && (value <= 9999.0))       this.rate = value;     else       processerror(string.format("{0} can not assigned rate property\n\nabort?", value));   } }  public double hours // define read/write hours property {     {     return this.hours;   }   set   {     if ((value >= 0) && (value <= 300.0))       this.hours = value;     else       processerror(string.format("{0} can not assigned hours property\n\nabort?", value));   } }  public double earnings {     {     return math.round(this.rate * this.hours, 2);   }  }  public double fica  // define result property {     {     return math.round(this.earnings * .07, 2);   } }  public double fedtax  // define result property {     {     return math.round(this.earnings * .22, 2);   } }  public double statetax  // define result property {     {     return math.round(this.earnings * .05, 2);   } }  public double netpay  // define result property {     {     return math.round(this.earnings - (this.fica + this.fedtax + this.statetax), 2);   } }  public string this[int propertyindex]   // define readonly indexer property {     {     string returnvalue = "";     switch (propertyindex)     {       case 0: returnvalue = this.id.tostring("d4"); break;       case 1: returnvalue = this.lastname; break;       case 2: returnvalue = this.firstname; break;       case 3: returnvalue = this.hiredate.tostring("mm/dd/yyyy"); break;       case 4: returnvalue = this.earnings.tostring("f2"); break;       case 5: returnvalue = this.fica.tostring("f2"); break;       case 6: returnvalue = this.fedtax.tostring("f2"); break;       case 7: returnvalue = this.statetax.tostring("f2"); break;       case 8: returnvalue = this.netpay.tostring("f2"); break;       default: processerror(string.format("{0} invalid " +                             "propertyindex value employee " +                             "class this[] indexer\n\nabort?", propertyindex)); break;     }     return returnvalue;   } }  public string this[string propertyname]   // define readonly indexer property {     {     string returnvalue = "";      switch (propertyname.toupper())     {       case "id"       :          returnvalue = this.id.tostring("d4");        break;       case "lastname" : case "last name": returnvalue = this.lastname;        break;       case "firstname": returnvalue = this.firstname;                         break;       case "hiredate" : returnvalue = this.hiredate.tostring("mm/dd/yyyy");   break;       case "earnings" : returnvalue = this.earnings.tostring("f2");           break;       case "fica"     : returnvalue = this.fica.tostring("f2");               break;       case "fedtax"   : returnvalue = this.fedtax.tostring("f2");             break;       case "statetax" : returnvalue = this.statetax.tostring("f2");           break;       case "netpay"   : returnvalue = this.netpay.tostring("f2");             break;       default: processerror(string.format("{0} invalid " +                             "propertyname value student " +                             "class this[] indexer\n\nabort?", propertyname)); break;     }     return returnvalue;   } }  public void copy(employee sourceemployee) // copy method {   this.id = sourceemployee.id; this.rate = sourceemployee.rate;   this.lastname = sourceemployee.lastname; this.firstname = sourceemployee.firstname;   this.hours = sourceemployee.hours;    this.hiredate.copy(sourceemployee.hiredate); }  public employee clone() {   return new employee (this); }  public int compareto(employee employee)           {                                            return this.id.compareto(employee.id); }  public static int compareids(employee employee1, employee employee2) {   return employee1.id.compareto(employee2.id); }  public static int comparenames(employee employee1, employee employee2) {   string string1 = employee1.lastname + employee1.firstname + employee1.id.tostring("d4");   string string2 = employee2.lastname + employee2.firstname + employee2.id.tostring("d4");   return string1.compareto(string2); }  public static int comparehiredates(employee employee1, employee employee2) {   string string1 = employee1.lastname + employee1.firstname + employee1.hiredate.tostring("");   string string2 = employee2.lastname + employee2.firstname + employee2.hiredate.tostring("");   return string1.compareto(string2); }  public static int compareearnings(employee employee1, employee employee2) {   string string1 = employee1.lastname + employee1.firstname + employee1.earnings.tostring("");   string string2 = employee2.lastname + employee2.firstname + employee2.earnings.tostring("");   return string1.compareto(string2); }  public static employee parse(string stringvalue) {   string[] words;   employee employee = new employee();    stringvalue = stringmethods.spacedelimit(stringvalue);   words       = stringvalue.split(' ');   employee.id        = int32.parse(words[0]);   employee.lastname  = words[1];   employee.firstname = words[2];   employee.hiredate  = date.parse(words[3]);   employee.rate      = double.parse(words[4]);   employee.hours     = double.parse(words[5]);   return employee; }  public override string tostring()  {   return string.format("{0:d4} {1,-15} {2,-15} {3,10:mm/dd/yyyy} {4,7:f} {5,7:f} {6,7:f} {7,7:f} {8,7:f} {9,7:f} {10,7:f}",                        this.id, this.lastname, this.firstname, this.hiredate,                        this.rate, this.hours, this.earnings, this.fica, this.fedtax,                        this.statetax, this.netpay); }  private void processerror(string message) {   dialogresult result;    result = messagebox.show(message, "error", messageboxbuttons.yesno, messageboxicon.error,                            messageboxdefaultbutton.button1);   if (result==dialogresult.yes)     consoleapp.exit(); }  } // end class employee  /****************************************************************/ /* 2. class employeelist : ienumerable                          */  /****************************************************************/  public class employeelist : ienumerable { public delegate int comparedelegate(employee employee1, employee employee2);  private int        capacity;  // data member private int        count;     // data member private employee[] items;     // data member  public employeelist() // default constructor {   this.capacity = 1;   this.count    = 0;   this.items    = new employee[1]; }   private employeelist(int capacityvalue) // initializing constructor {   if (capacityvalue>=1)         {      this.capacity = capacityvalue;     this.count    = 0;     this.items    = new employee[capacityvalue];   }   else     processerror(string.format("{0} can not capacity of employeelist object\n\nabort?",capacityvalue)); }  public employeelist(employeelist sourcelist) // copy constructor {   this.copy(sourcelist); }  public int count // define read-only count property {     {     return this.count;   } }  public employee this[int index]   // define read/write this[] indexer property {       {       if ((index>=1) && (index<=count))      return this.items[index-1];     else     {       processerror(string.format("employeelist [] index must between 1 , {0}\n\nabort?",this.count));       return default(employee);     }   }   set   {     if ((index >= 1) && (index <= this.count))       this.items[index - 1] = value;     else       processerror(string.format("employeelist [] set index must between 1 , {0}\n\nabort?", this.count));   } }  public bool empty // return true (false) if list (not) empty {     {     return (this.count == 0);   } }  public ienumerator getenumerator()      // ienumerable interface implementation: {                                       // declaration of getenumerator() method,   (int i=1; i<=this.count; i++)     // needed give meaning "foreach"     yield return this[i];               // control construct. }   public void clear()  // remove list elements {   this.capacity = 1;   this.count = 0;   this.items = new employee[1]; }  public void copy(employeelist sourcelist)  // approach correct {   this.clear();   foreach (employee employee in sourcelist)     this.add(employee.clone()); }  public employeelist clone() {   return new employeelist(this);  }  private void increasecapacity() {   employeelist templist;    templist = new employeelist(2 * this.capacity);   foreach (employee employee in this)     templist.add(employee);   this.capacity = templist.capacity;   this.count = templist.count;   this.items = templist.items; }  public void add(employee employee) {   this.insertat(this.count+1, employee); }  public void insertat(int position, employee employee) {   int i;    if ((position >= 1) && (position <= this.count + 1))   {     if (this.count == this.capacity)       this.increasecapacity();     this.count++;     (i = this.count; > position; i--)       this[i] = this[i - 1];     this[position] = employee;   }   else     processerror(string.format("employeelist insertat index must between 1 , {0}\n\nabort?", this.count + 1)); }  public employee removeat(int position) {   int i;   employee employee = null;    if ((position >= 1) && (position <= this.count))   {     employee = this[position];     (i = position; < this.count; i++)       this[i] = this[i + 1];     this.count--;   }   else     processerror(string.format("employeelist removeat index must between 1 , {0}\n\nabort?", this.count));   return employee; }  private void processerror(string message) {   dialogresult result;    result = messagebox.show(message, "error", messageboxbuttons.yesno, messageboxicon.error,                            messageboxdefaultbutton.button1);   if (result == dialogresult.yes)     consoleapp.exit(); }  public void reverse() {   int i;   employee tempvalue;    (i = 1; <= this.count / 2; i++)   {     tempvalue = this[i];     this[i] = this[this.count + 1 - i];     this[this.count + 1 - i] = tempvalue;   } }  public int locate(employee employee) // locate , return list index  {                                    // of data in list.   int listindex = 1;                      while ((listindex <= this.count) && (this[listindex].compareto(employee) < 0))     listindex++;   if (listindex > this.count)     listindex = ~listindex;    else if (this[listindex].compareto(employee) > 0)     listindex = ~listindex;   return listindex; }  public int locate(employee employee, comparedelegate comparemethod) // locate , return list index  {                                                                   // of data in list.   int listindex = 1;                                              // uses comparedelegate method.       while ((listindex <= this.count) && (comparemethod(this[listindex], employee) < 0))     listindex++;   if (listindex > this.count)     listindex = ~listindex;   else if (comparemethod(this[listindex], employee) > 0)     listindex = ~listindex;   return listindex; }  public void sort()   // uses employee class compareto method   {   int i, j, k;   employee temp;    (i = 1; <= (this.count - 1); i++)   {     k = i;     (j = (i + 1); j <= this.count; j++)      if (this[j].compareto(this[k]) < 0)         k = j;     if (k > i)     {       temp = this[k];       this[k] = this[i];       this[i] = temp;     }   } }  public void sort(comparedelegate comparemethod)  // uses comparedelegate method.   {   int i, j, k;   employee temp;    (i = 1; <= (this.count - 1); i++)   {     k = i;     (j = (i + 1); j <= this.count; j++)       if (comparemethod(this[j], this[k]) < 0)         k = j;     if (k > i)     {       temp = this[k];       this[k] = this[i];       this[i] = temp;     }   } }  public double total(string propertyname) {   double total = 0.0;    foreach (employee employee in this)     total += double.parse(employee[propertyname]);   return total; }  public double mean(string propertyname) {   return this.total(propertyname) / this.count; }  public double max(string propertyname) {   int i;   double max = double.parse(this[1][propertyname]);    (i = 2; <= this.count; i++)     if (double.parse(this[i][propertyname]) > max)       max = double.parse(this[i][propertyname]);   return max; }  public double min(string propertyname) {   int i;   double min = double.parse(this[1][propertyname]);    (i = 2; <= this.count; i++)     if (double.parse(this[i][propertyname]) < min)       min = double.parse(this[i][propertyname]);   return min; }  public int assignid() {   int returnvalue = 1;    if (this.count>0)     returnvalue =  (int) this.max("id") + 1;   return returnvalue; }  public void input(streamreader filein) {   string linein;    while ((linein=filein.readline())!=null)     this.add(employee.parse(linein)); }  public void printreport(streamwriter fileout, string orderdescriptor) {   int indent = (63 - orderdescriptor.length) / 2;    orderdescriptor = "".padleft(indent) + orderdescriptor;   fileout.writeline("                        employee report                         ");   fileout.writeline(orderdescriptor);   fileout.writeline("                          {0:mm/dd/yyyy}", date.today);   fileout.writeline();   fileout.writeline("                          jon ernst                             ");   if (!this.empty)   {     fileout.writeline(" id     last name      first name       hired    earnings    fica    fed tax  state tax  net pay ");     fileout.writeline("---- --------------- --------------- ---------- --------- --------- --------- --------- ---------");     foreach (employee employee in this)       fileout.writeline("{0:d4} {1,-15} {2,-15} {3,10:mm/dd/yyyy} {4,7:f} {5,7:f} {6,7:f} {7,7:f} {8,7:f}",                         employee.id, employee.lastname, employee.firstname, employee.hiredate,                         employee.earnings, employee.fica, employee.fedtax, employee.statetax, employee.netpay);     fileout.writeline("                                                     --------- -------- --------- --------- ---------");     fileout.writeline("{0,-52} {1,7:f} {2,7:f} {3,7:f} {4,7:f} {5,7:f}", "mean", this.mean("earnings"), this.mean("fica"), this.mean("fed tax"), this.mean("state tax"), this.mean("net pay"));     fileout.writeline("{0,-52} {1,7:f} {2,7:f} {3,7:f} {4,7:f} {5,7:f}", "maximum", this.max("earnings"), this.max("fica"), this.max("fed tax"), this.max("state tax"), this.max("net pay"));     fileout.writeline("{0,-52} {1,7:f} {2,7:f} {3,7:f} {4,7:f} {5,7:f}", "minimum", this.min("earnings"), this.min("fica"), this.min("fed tax"), this.min("state tax"), this.min("net pay"));     fileout.writeline();     fileout.writeline("count = {0}", this.count);   }   else     fileout.writeline("the list empty.");   fileout.writeline(); }  } // end class employeelist  } // end namespace libemployee1 

visual studio pointing out stack overflow error @ method:

public date hiredate  // define read/write hiredate property {     {  **<=== visual studio points overflow error line**     return this.hiredate;     }   set   {     this.hiredate.copy(value);   } } 

you have answer right there in code, in hiredate property, you're returning value of hiredate property, in turn return value of hiredate property, , on..! want return value of backing field.

public datetime hiredate {         {         return this.hiredate;     }     set     {         this.hiredate = value;     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -