-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCopy_Constructor.cs
50 lines (43 loc) · 1.02 KB
/
Copy_Constructor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace copycontrustor
{
class data
{
string name;
int id;
// original construstor
public data(string n,int i)
{
name = n;
id = i;
}
// copy construstor
public data(data a)
{
name = a.name;
id = a.id;
}
public void show()
{
Console.WriteLine("Name : "+name);
Console.WriteLine("Id : "+id);
Console.WriteLine("------------------------------");
}
}
class Program
{
static void Main(string[] args)
{
// object of original constructor
data obj = new data("ali", 1234);
obj.show();
// object of copy constructor
data copy = new data(obj);
copy.show();
}
}
}