Example for copy Constructor:
//Fileno: demo_49
//Author: SURESH BABU
//Reference: Copy Constructor
using System;
namespace demo_49
{
public class CopyConstruct
{
private int x, y;
public CopyConstruct(int a, int b)
{
x=a;
y=b;
}
public CopyConstruct(CopyConstruct T)
{
x= T.x;
y = T.y;
}
public void show()
{
Console.WriteLine("The value of x and y are {0} and {1}",x,y);
}
public void print()
{
Console.WriteLine("The value of a and b are {0} and {1}",x,y);
}
}
class Program
{
static void Main(string[] args)
{
CopyConstruct t3 = new CopyConstruct(80,90);
CopyConstruct t2 = new CopyConstruct(t3);
t2.show();
t2.print();
}
}
}
//Fileno: demo_49
//Author: SURESH BABU
//Reference: Copy Constructor
using System;
namespace demo_49
{
public class CopyConstruct
{
private int x, y;
public CopyConstruct(int a, int b)
{
x=a;
y=b;
}
public CopyConstruct(CopyConstruct T)
{
x= T.x;
y = T.y;
}
public void show()
{
Console.WriteLine("The value of x and y are {0} and {1}",x,y);
}
public void print()
{
Console.WriteLine("The value of a and b are {0} and {1}",x,y);
}
}
class Program
{
static void Main(string[] args)
{
CopyConstruct t3 = new CopyConstruct(80,90);
CopyConstruct t2 = new CopyConstruct(t3);
t2.show();
t2.print();
}
}
}
No comments:
Post a Comment