Hi,
I have been programming C# for some time, and i recently learned about constructors and objects, but didn't fully understand.
Can anyone please help me understand this, and please spell it out. I have tried googling it, but couldn't really find anything, that made me understand it.

-What is a constructor?
-What is a object?
-When should i use a constructor?
-When should i use a object?

This is a HUGE topic. I will atempt a short explanation.

A constructor is a special function called to create an "object" of a specific class.
Lets look at an example of a class called "Fruit":

public Class Fruit {
    String FruitType;
    String Color;

    public Fruit() {
        FruitType='Unknown';
        FruitColor='Unknown'
    }

    public Fruit(string typ, string col) {
        FruitType = typ;
        Color = col;
    }
}

There are two constructors, public Fruit(....
The first takes no parameters and returns an instance of a Fruit Class with type and color='Unknown'. That instance also called an "object" of type Fruit. usage example:

Fruit apple;
apple = new Fruit();
apple.FruitType='Apple';
apple.Color = 'Red'

"apple" is an object.

The second takes two parameters, to make it simpler to use. Usage example:

Fruit apple;
apple = new Fruit("Apple","Green");

"apple" is an object just like above.

Almost every Class will have a default constructor with no parameters. Not all classes have an other constructors.

There is so much more to classes and objects it could not possibly be covered here. There are thousands of books on C# programming and classes.

HTH,
Sean

commented: Thanks for the Clif note version. +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.