Results 1 to 2 of 2

Thread: What is mean by shallow copy in Clone() method

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Answers
    1

    What is mean by shallow copy in Clone() method

    public class Product
    {
    public Product(int id, int name)
    {
    Id=id;
    Name = name;
    }
    int Id;
    string Name;
    }

    public class ProductCollection : CollectionBase, ICloneable
    {
    //Ic collection Obect to Hold the Product Object
    }

    public static void main
    {
    ProductCollection A = New ProductCollection();
    for(int i =1; I < 6;i++)
    {
    Product product = new prodcut(i, "Name" + i.ToString());
    }
    ProductCollection B = A;
    ProductCollection C = A.Clone();
    //Now I cache this object

    //Let me change the value of the one product
    ((Product)b[1]).Id = 10;
    //Questions
    //In this case value whatever cached will be changed or not.
    //What is the difference between Objce B and C;

    }

    //In this case value whatever cached will be changed or not.
    //What is the difference between Object B and C;


  2. #2
    Junior Member
    Join Date
    Nov 2009
    Answers
    4

    Re: What is mean by shallow copy in Clone() method

    I think shallow copy of the clone method means that the Clone method creates a copy of the data when they are primitive in nature like integer,long,char,enum, structure and so on.It does not imply to datatypes that are not of primitive type like userdefined type such as Objects,Arrays,Strings and so on.I mean that Shallow copy copies the value and not the address during the creation of Clone object through Clone method.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact