google.com, pub-5796814184912345, DIRECT, f08c47fec0942fa0 Copy Constructor in c#.net and class diagram with example program code
02 05 08

Copy Constructor in c#.net and class diagram with example program code

Copy Constructor in  c#.net and class diagram with example program code : Here dotnetportal9.blogspot.in blog gives you info about Copy Constructor in  c#.net and class diagram and also we will give beatiful example program to understand Copy Constructor easyly

Copy Constructor in  c#.net :-

  • Copy Constructor is used to copy the data of existing object in to newly created object
  • Example to Copy Constructor.

Class Diagram:-
                                                                                                                   
                                                                                                                      
Employee4
Int Empid
String Ename
String Eadderse
Int Eage
Public employee4()
Public employee4(Employee4 obj1)
Public  void DisplayEmpData()


Copy Constructor in  with example program c#.net :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CAConstructors
{
    class employee4

     {
        int Empid, Eage;
        string Ename, EAddress;

        public employee4()
        {
            Console.WriteLine("Enter Employee Details:-");
            this.Empid=Convert.ToInt32(Console.ReadLine());
            this.Ename=Console.ReadLine();
            this.EAddress=Console.ReadLine();
            this.Eage=Convert.ToInt32(Console.ReadLine());
        }
        public employee4(employee4 obj1)
        {
            this.Empid=obj1.Empid;
            this.Ename=obj1.Ename;
            this.EAddress=obj1.EAddress;
            this.Eage=obj1.Eage;
        }
        public void DisplayEmpData()
        {
            
            Console.WriteLine("Employee id is :-" + Empid);
            Console.WriteLine("Employee Name is :-" + Ename);
            Console.WriteLine("Employee Address is :-" + EAddress);
            Console.WriteLine("Employee age is :-" + Eage);
        }
    }
    class CopyConstructor
    {
          static void Main(string[] args)
          {
              employee4 obj1=new employee4();
              employee4 obj2=new employee4(obj1);
              obj1.DisplayEmpData();
              obj2.DisplayEmpData();
              Console.ReadLine();
          }
    }
}
Output:-



  • Without using copy constructor we can also the data of existing objects in to newly created object  by writing a statement like

Empoyee4 obj2=obj1;

  • when we use this statement by default all data fields data of obj1 will be copied into obj2.
  • But if we want to restrict copying of some data fields data it is not possible for this purpose copy constrictor is suitable.
  • Realtime:-
Copy Constructor is used in real time in following switchvations:-

  • If an object contains data which is stored by getting from database (or) from some remote place over the network for newly created object if we want the same data it is preferable to use copy constructor instead of using getting the data from data base (or) remote place over the network.

Latest Walkins 2013(updated every day )



Hyderabd Walkins 2013

walkins in chennai2013-14

walkins in Chandigarh2013

Walkins In Mumbai 2013

pune In Walkins 2013

Kolkata in walkins 2013

Ahmedabad JOBS 2013

Banglore walkins

Dotnet jobs

09 10

0 comments:

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP