C# Overloading Invalid Arguments -


i'm quite new c# sorry if coding bit dodgy! keep getting 3 errors people application.
errors caused trying convert int , bools strings, i'm not sure how i'm meant change it, if guys give me hand, great thanks! tips appreciated! errors keep reoccurring are:

  • error 1: best overloaded method match 'lab5b.person.person(string, int, string, string, bool, string)' has invalid arguments

  • error 2: argument 2: cannot convert 'string' 'int'

  • error 3: argument 5: cannot convert 'method group' 'bool'

my code:

public partial class _default : page     {          protected void button1_click(object sender, eventargs e)         {             response.write("you have added person!");              person p = new person(textbox1.text, textbox2.tostring(), textbox3.text, textbox4.text, dropdownlist1.tostring, textbox5.text);         }     } 

and person class:

class person {     private string name;     private int age;     private string dob;     private string telno;     private bool gender;     private string address;      public person(string name, int age, string dob, string telno, bool gender, string address)     {         name = name;         age = age;         dob = dob;         telno = telno;         gender = gender;         address = address;     }      public int age { get; set; }     public string name { get; set; }     public string dob {get; set;}     public string telno {get; set;}     public bool gender {get; set;}     public string address {get; set;}      public string presentperson()     {      } } 

you have number of issues.

  • first, passing value textbox2 string when "age" parameter requires int.
  • second, passing dropdownlist1 value method group because did not close out params ()
  • third, if had called .tostring() correctly, have been passing string value argument expecting bool.
  • fourth, referencing control textbox2 , not value of textbox give unexpected incorrect result.
  • fifth, not retrieving selected value of dropdown list rather attempting pass control itself.

.

protected void button1_click(object sender, eventargs e) {     response.write("you have added person!");      person p = new person(textbox1.text, int.parse(textbox2.text.tostring()),          textbox3.text, textbox4.text, bool.parse(dropdownlist1.selectedvalue.tostring()),          textbox5.text); } 

for gender, code making assumption drop down list values either true or false can appropriately parsed, without null entries or entries different value (such male / female).

also, it's worth noting these parses throw exception if cannot properly. use tryparse , validate data think is.

protected void button1_click(object sender, eventargs e) {     response.write("you have added person!");      int age;     bool gender;      int.tryparse(textbox2.text.tostring(), out age);     bool.tryparse(dropdownlist1.selectedvalue, out gender);      person p = new person(textbox1.text, age, textbox3.text, textbox4.text, gender,                      textbox5.text); } 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -