Friday, 6 April 2012

Icloneable interface

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

namespace ConsoleApplication
{
    public class Persondetails : ICloneable
    {
        private string name;
        private List contactnumbers;
        public Persondetails(string n)
        {
            name = n;
            contactnumbers = new List();
        }
        public void Addcontactnumber(string number)
        {
            contactnumbers.Add(number);
        }
        public object Clone()
        {
            Persondetails cloneobject = new Persondetails(name);
            foreach (string num in contactnumbers)
            {
                cloneobject.contactnumbers.Add(num);
            }
            return cloneobject;
        }
        static void Main(string[] args)
        {
            Persondetails originaldetails = new Persondetails("ruby");
            originaldetails.Addcontactnumber("number1");
            originaldetails.Addcontactnumber("number2");
            Console.WriteLine(originaldetails.name);
            Persondetails clonedetails = (Persondetails)originaldetails.Clone();
            originaldetails.Addcontactnumber("number3");
            clonedetails.Addcontactnumber("number4");
            Console.WriteLine(originaldetails.contactnumbers[0] + "" + originaldetails.contactnumbers[1] + "" + originaldetails.contactnumbers[2]);

            Console.WriteLine(clonedetails.name);
            Console.WriteLine(clonedetails.contactnumbers[0] + "" + clonedetails.contactnumbers[1] + clonedetails.contactnumbers[2]);
        }
    }
}

No comments:

Post a Comment

CRUD operations using AngularJS in Asp.Net MVC

In this article I will show you how to perform CRUD operations in Asp.Net MVC5 using AngularJS. Add AngularJS using the Manage Nuget Pack...