Re: ArrayList consisting of objects
- From: "Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx>
- Date: Thu, 14 Sep 2006 07:09:08 +0200
In addition to Steven,
Have a look at the keyword "new"
"new" tells that it is a new array (you are instancing that from a Class
running its instancing method)
Without it it is telling that it is referencing (setting the reference) to
an existing one.
Cor
"ZS" <ZS@xxxxxxxxxxxxxxxxxxxxxxxxx> schreef in bericht
news:035E8687-4045-4287-A56C-6E43810D9F16@xxxxxxxxxxxxxxxx
Hi,
Here is a piece of code where I have a class by name SomeClass
array1 consists of objects of the type SomeClass
array2 is intialized with contents of array1.
Why does changes made to the object of array2 affect the same object in
array1.
The o/p for the following should be just '1' but why is it '11'?
ArrayList array1 = new ArrayList();
array1.Add(new SomeClass("1"));
array1.Add(new SomeClass("2"));
ArrayList array2 = new ArrayList();
array2 = array1;
array1.Add(new SomeClass("3"));
SomeClass al = (SomeClass) array2[0];
al.AlName = "11";
SomeClass newObj = (SomeClass) array1[0];
MessageBox.Show (newObj.AlName);
.
- Prev by Date: Re: Download the JAVA , .NET and SQL Server interview with answers
- Next by Date: Re: Where to declare Public variable
- Previous by thread: Download the JAVA , .NET and SQL Server interview with answers
- Next by thread: Re: ArrayList consisting of objects
- Index(es):
Relevant Pages
|