Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What is constructor ? On which saturation we can use constructor. Please give me practical example with code.

Can i done the process without constructor where require constructor?

Thanks
pramod
Posted
Comments
[no name] 1-Sep-14 6:09am    
What was unclear to you when you read the documentation for constructors?

 
Share this answer
 
Constructors enable the programmer to set default values, limit instantiation, and write code that is flexible and easy to read.
You can find very clean and deeply study of Constructors on MSDN.
Using Constructors
Constructors (C# Programming Guide)
 
Share this answer
 
A constructor in a class is a special type have the same name as the declaring class.
It prepares the new object for use.
It differs from a method in that it has no explicit return type.
Using overloading the constructor in that there can be more than one constructor for a class.
Constructor creates objects in a special memory structure called heap for reference types.
Value types (such as int, double etc.), are created in a sequential structure called stack.
Constructors cannot be synchronized abstract or static.
Example
public class CC
{
    private int a;
    private string b;

    // Constructor
    public CC() : this(42, "string")
    {
    }

    // Overloading a constructor
    public CC(int a, string b)
    {
        this.a = a;
        this.b = b;
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900