Passing a parameter to a class

  • Thread starter Thread starter Doug
  • Start date Start date
D

Doug

I have probably a simple question:

How do I declare a class to have a parameter of a certain
type? I want to declare frmAppointment to pass a
parameter of DateTime so when I call it, I call do this:

frmAppointment(dateTime)

example declaration:

public class frmAppointment : System.Windows.Forms.Form

Thanks,
Doug
 
Use a constructor to do this.

public class frmAppointment : System.Windows.Forms.Form

{

DateTime mydatetime;


//default constructor

public frmAppointment()

{

}

//constructor with arguments

public frmAppointment(DateTime dt)

{

this.mydatetime = dt;

}

}
 
Doug said:
How do I declare a class to have a parameter of a certain
type?

Classes don't have parameters, nor do you call classes. You call
methods and constructors (and effectively properties). You might have
meant a constructor, in which case see the other post in this thread
and read
http://www.pobox.com/~skeet/csharp/constructors.html

If that doesn't answer your question, give a bit more detail and I'll
see if I can help you further.
 
Back
Top