Users Pricing

blog

Home Blogs Copy Constructor in C# – MindStick

Copy Constructor in C#

Amit Singh 7320 12 May 2011 Updated 18 Sep 2014

This is the one type of constructor. A copy constructor creates an object by copying variables from another object.

for example
we pass one item object to the item constructor so that the new item object has the same value as the old one.
copy constructor defined as :

public Student(Student stud)
{
name=stud.name;
age=stud.age;
}

the copy constructor is invoked by instantiating an object of type Student and passing it the object to be copied.
example
Student stud1=new Student(stud2);
Now, stud1 is a copy of stud2.


Amit Singh

Other


2 Comments


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md