IndiaBIX.com
Search

C# Programming - Constructors - Discussion

@ : Home > C# Programming > Constructors > General Questions - Discussion

Read more:

"Love is like a war, Easy to begin Hard to end."
- (Proverb)
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

Explanation:

No answer description available for this question.


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

Sundar said: (Sun, Jul 3, 2011 03:01:01 AM)    
 
@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: (Wed, Feb 15, 2012 10:35:03 AM)    
 
C# provides copy constructor also.
So ans should be A &B

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

Sunil said: (Fri, Nov 2, 2012 01:53:27 AM)    
 
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: (Sun, Sep 29, 2013 04:05:15 PM)    
 
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: (Tue, Oct 29, 2013 11:36:35 AM)    
 
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: (Sun, Nov 17, 2013 11:06:02 AM)    
 
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: (Sat, Mar 1, 2014 12:58:27 PM)    
 
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: (Mon, Jul 14, 2014 06:07:22 AM)    
 
C# doesn't provide a copy constructor for objects, but you can write one yourself.

Write your comments here:
Name *:     Email:


© 2008-2014 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!