C# | Copy Constructor Last Updated : 04 Dec, 2021 Comments Improve Suggest changes Like Article Like Report A constructor that creates an object by copying variables from another object or that copies the data of one object into another object is termed as the Copy Constructor. It is a parameterized constructor that contains a parameter of the same class type. The main use of copy constructor is to initialize a new instance to the values of an existing instance. Normally, C# does not provide a copy constructor for objects, but if you want to create a copy constructor in your program you can create according to your requirement.Syntax: class Class_Name { // Parameterized Constructor public Class_Name(parameter_list) { // code } // Copy Constructor public Class_Name(Class_Name instance_of_class) { // code } } Example 1: CSharp // C# program to illustrate the use // of copy constructor using System; namespace simplecopyconstructor { class technicalscripter { // variables private string topic_name; private int article_no; // parameterized constructor public technicalscripter(string topic_name, int article_no) { this.topic_name = topic_name; this.article_no = article_no; } // copy constructor public technicalscripter(technicalscripter tech) { topic_name = tech.topic_name; article_no = tech.article_no; } // getting the topic name and // number of articles published public string Data { get { return "The name of topic is: " + topic_name + " and number of published article is: " + article_no.ToString(); } } } // Driver Class public class GFG { // Main Method static public void Main() { // creating object t1 // and provide value to the object technicalscripter t1 = new technicalscripter(" C# | Copy Constructor", 38); // Creating object t2 and // copy the data of t1 object // into t2 object technicalscripter t2 = new technicalscripter(t1); Console.WriteLine(t2.Data); Console.ReadLine(); } } } Output: The name of topic is: C# | Copy Constructor and number of published article is: 38 Example 2: CSharp // C# Program to illustrate the use // of Copy constructor using System; namespace copyConstructorExample { class Vehicle { // variables private string name; private string color; private int quantity; // Copy constructor public Vehicle(Vehicle a) { name = a.name; color = a.color; quantity = a.quantity; } // Parameterized constructor public Vehicle(string name, string color, int quantity) { this.name = name; this.color = color; this.quantity = quantity; } // Get details of Vehicles public string DetailsofVehicle { get { return "Type: " + name.ToString() + "\nColor: " + color.ToString() + "\nQuantity: " + quantity.ToString(); } } // Main Method public static void Main() { // Create a new object. Vehicle v1 = new Vehicle("Bike", "Black", 40); // here is v1 details are copied to v2. Vehicle v2 = new Vehicle(v1); Console.WriteLine(v2.DetailsofVehicle); } } } Output: Type: Bike Color: Black Quantity: 40 Comment More infoAdvertise with us Next Article C# | Copy Constructor A ankita_saini Follow Improve Article Tags : Misc C# CSharp-OOP Practice Tags : Misc Similar Reads C# Constructors Constructor is a special method of the class which gets automatically invoked whenever an instance of the class is created. Constructors in C# are fundamental components of object-oriented programming. Like methods, It contains the collection of instructions that are executed at the time of Object c 5 min read C# | Constructor Overloading Prerequisite: Constructors in C# It is quite similar to the Method Overloading. It is the ability to redefine a Constructor in more than one form. A user can implement constructor overloading by defining two or more constructors in a class sharing the same name. C# can distinguish the constructors w 8 min read Structures in C++ C++ Structures are used to create user defined data types which are used to store group of items of different data types.SyntaxBefore using structure, we have to first define the structure using the struct keyword as shown:C++struct name{ type1 mem1; type2 mem2; ... };where structure name is name an 8 min read Passing a Vector to Constructor in C++ Just like any other data, we can also pass a vector to a constructor of the desired class. We can pass it by value or by reference. What we do with it depends on our requirement. The following are some of the common cases:Copy Data to Member VectorIf we want to store the copy of the vector in the cl 3 min read std::is_trivially_copy_constructible in C/C++ The std::is_trivially_copy_constructible template is a type that can be trivially constructed from a value or reference of the same type. This includes scalar types, trivially copy constructible classes and arrays of such types. This algorithm is about to test whether a type is trivially copied cons 2 min read Like