No Overload in method?

Last post 04-27-2007 7:40 AM by camper. 4 replies.

Sort Posts:

  • No Overload in method?

    04-26-2007, 9:59 AM
    • Loading...
    • camper
    • Joined on 04-28-2006, 8:48 AM
    • Posts 74

    When this code is run it results in an error saying "No overload for method 'Friends' takes '0' arguments - please can anybody resolve?

    Hi does anybody know how I can resolve this error?

    code for class friends

    public class Friends

    {

    public string id;

    public string name;

     public Friends (string id, string name)

    { this.name = name;

    this.id = id;

    }

    }

     

    then page code:

    protected void btnUseClass_Click(object sender, EventArgs e)

    { Friends f = new Friends();

    f.id = tbID.Text;

    f.name = tbName.Text;

    lblID.Text = f.id;

    lblName.Text = f.name;

    }

    }

    When this code is run it results in an error saying "No overload for method 'Friends' takes '0' arguments - please can anybody resolve?

  • Re: No Overload in method?

    04-26-2007, 12:11 PM
    • Loading...
    • dauger
    • Joined on 06-17-2002, 10:09 AM
    • Saint Paul, MN
    • Posts 112
    When creating a class, if you specify a constructor that takes arguments, which you have with your friends(string id, string name), you will no longer automatically have a zero argument constructor of Friends(). You must specify the 0 argument constructor in your class.
  • Re: No Overload in method?

    04-26-2007, 4:52 PM
    • Loading...
    • camper
    • Joined on 04-28-2006, 8:48 AM
    • Posts 74
    How do I specify that in code?  thx
  • Re: No Overload in method?

    04-26-2007, 5:05 PM
    • Loading...
    • dauger
    • Joined on 06-17-2002, 10:09 AM
    • Saint Paul, MN
    • Posts 112
    Here you go Smile
    public class Friends
    {
       public string id;
       public string name;
    
       //Empty 0 arg constructor
       public Friends() 
       {
          // do nothing in this case;
       }
    
       public Friends(string id, string name)
       {
          this.name = name;
          this.id = id;
       }
    }
     
  • Re: No Overload in method?

    04-27-2007, 7:40 AM
    Answer
    • Loading...
    • camper
    • Joined on 04-28-2006, 8:48 AM
    • Posts 74
    Big Smile Thx
Page 1 of 1 (5 items)
Microsoft Communities
Page view counter