Results 1 to 5 of 5

Thread: constructor

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    constructor

    I read that every class can have a constructor (or multiple constructors ).

    I have a form1 class and this is the start up form.

    I want to try and see how the constructor for his object works, and I added the following code.

    public class Form1 : System.Windows.Forms.Form
    {
    public void Form1()
    {
    Console.WriteLine("Constructor");
    }
    }

    static void Main()
    {

    Application.Run(new Form1());
    }
    Error: Member names cannot be same as the member types

    what does that mean?

    nath

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: constructor

    Constructors don't have a return type. It would just be...
    Code:
    public Form1() {
    //...
    }
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Re: constructor

    but the error message is different .

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: constructor

    Okay...and what would it be?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Re: constructor

    thanks . it works.

    nath

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width