Constructor
-
:rose:What is constructor and how to use it pls help me about constructor with simple Example Thanks,
-
:rose:What is constructor and how to use it pls help me about constructor with simple Example Thanks,
imran_Shaikh wrote:
What is constructor
A constructor initialises a new instance of an object.
imran_Shaikh wrote:
how to use it
public class MyCoolClass
{
public MyCoolClass()
{
// This is a constructor. It is just a special type of method.
// Initialise the new instance of the class here
}
}class Program
{
static void Main()
{
MyCoolClass aCoolObject = new MyCoolClass();
}
}
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
:rose:What is constructor and how to use it pls help me about constructor with simple Example Thanks,
Basically, constructors are special methods that are called when an instance of a class is created. Unless the class is marked 'static', a public default (parameterless) constructor is created for it by the compiler. Here is an article that has examples.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’