C# Programming - Constructors - Discussion

Discussion :: Constructors - General Questions (Q.No.1)

1. 

Which of the following statements is correct?

[A]. A constructor can be used to set default values and limit instantiation.
[B]. C# provides a copy constructor.
[C]. Destructors are used with classes as well as structures.
[D]. A class can have more than one destructor.

Answer: Option A

Explanation:

No answer description available for this question.

Tulsi said: (Jul 3, 2011)  
C# also provide copy construvtor so ans. Should be a & b.

Sundar said: (Jul 3, 2011)  
@Tulsi

Unlike some languages, C# does not provide a copy constructor. If you create a new object and want to copy the values from an existing object, you have to write the appropriate method yourself.

Source: http://msdn.microsoft.com/en-us/library/ms173116(v=vs.80).aspx

Hema said: (Feb 15, 2012)  
C# provides copy constructor also.
So ans should be A &B

Srikanth said: (Feb 17, 2012)  
C# provides copy constructor also.
So ans should be A &B

Sunil said: (Nov 2, 2012)  
class Person
{
private string name;
private int age;

// Copy constructor.
public Person(Person previousPerson)
{
name = previousPerson.name;
age = previousPerson.age;
}

// Instance constructor.
public Person(string name, int age)
{
this.name = name;
this.age = age;
}

// Get accessor.
public string Details
{
get
{
return name + " is " + age.ToString();
}
}
}

class TestPerson
{
static void Main()
{
// Create a new person object.
Person person1 = new Person("George", 40);

// Create another new object, copying person1.
Person person2 = new Person(person1);
System.Console.WriteLine(person2.Details);
}
}

Akash said: (Sep 29, 2013)  
Generally, constructors are of three types. But C# doesn't support copy constructor.

- Default Constructor(Non-Parametrized constructor).

- Parametrized Constructor.

- Copy Constructor.

Gaurav Balyan said: (Oct 29, 2013)  
C# does not provide Copy Constructor and if you need one you have to do it by using a method, and you can also have a ICloneable Interface to implement the functionality.

Amaan said: (Nov 17, 2013)  
C sharp does provide a copy construct but the prime work for the constructor is to assign values to the variables as c# you cannot use a variable without declaring assigning a value where the automatic initialization happens in the case of instance variable or global variable.

Rajeev Ranjan Kumar(Raju) said: (Mar 1, 2014)  
C# provides three types of constructor:
1st 1 is: Default Const.
2nd 1 is: Param Const.
And 3rd 1 is: Copy Const.
So Answer Should be A & B.

Neeraj Sharma said: (Jul 14, 2014)  
C# doesn't provide a copy constructor for objects, but you can write one yourself.

Bhavani said: (Oct 17, 2014)  
C# doesn't provide copy constructor, every class have implicit constructor.

Arul said: (Mar 20, 2015)  
C# provide a copy constructor and C# class have more than one constructor. So answer B & D.

Hema said: (Apr 14, 2015)  
C# provides copy constructor also.

So, A and B both are correct.

David said: (Oct 5, 2015)  
Constructors is automatically invoked when the class objects is initiated.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.


Have a question?

Ask your question now !

Create your own website ?

Web Hosting Services in India