all groups > c# > march 2007 >
You're in the

c#

group:

Question about visibility/ modifications of objects


Re: Question about visibility/ modifications of objects justin creasy
3/1/2007 5:11:24 PM
c#:
[quoted text, click to view]

I think your problem might be in the Constructor for Algo. When you
assign the values of dList to I guess a local dList in the Algo
instance do you assign just the values? Please post the Constructor
and any other needs methods in the Algo class.
Re: Question about visibility/ modifications of objects justin creasy
3/1/2007 6:18:45 PM
[quoted text, click to view]

I am not very familiar with the DocumentList control but it sounds
like when you write

dList_ =3D dList;

it is copying a reference to dList, not the values of everything in
dList. Read this MSDN article on how to use the DocumentList and see
if it helps. Also look around to find out if DocumentList is passed as
reference or value.

http://msdn2.microsoft.com/en-us/library/ms172535.aspx
Question about visibility/ modifications of objects Martin Pöpping
3/1/2007 11:26:06 PM
Hello,

I´ve a general question about the visibility and modification of an object.

I will try to explain it in my code, where I have the problem:


DocumentList dList = initDocuments(thesaurus);

for (int i = 0; i < testRuns_; i++)
{
Algo algo = new Algo(dList, 1.1, anzahlCluster, thesaurus, initType_);
run = algo.run(maxIter, epsilon);
tests.add(i, run);
}


In my DocumentList dList I have a List of objects which I create with
initDocuments().

In the for-loop I am removing some objects (documents) out of the
DocumentList with my method algo.run.

Let´s say my DocumentList has a size of 100 _before_ entering the loop.
If I call algo.run, I am removing 4 Documents out of my DocumentList.
So I have 96 Documents in my list.

But I thought, that I am removing these documents _only_ in my object
"Algo" and not in my object dList which I have created _before_ entering
the for-loop.

In other words:

I want to have 100 Documents in my DocumentList.
Then I am doing the first loop iteration, removing 4 but when I am doing
my second iteration, I want to have 100 Documents again and not 96.


But that is exactly what happens.

If I run my loop a second time, I only have 96 Documents and not 100
Documents.


Well.. I hope I explained it right and somebody understands my problem.

My general question is about visibility and modifications of objects.
How can I reach that my object "algo" does not change my object "dList"?
In other words... the object "algo" should work with it´s own copy of
the object dList.


Regards,

Re: Question about visibility/ modifications of objects Martin_Pöpping
3/2/2007 3:07:37 AM
justin creasy schrieb:

[quoted text, click to view]


[quoted text, click to view]

Here is the Constructor:

private DocumentList dList_;

public A.go(DocumentList dList, double fuzzyness /*...*/)
{
logger_.Info("Initialisiere...);
dList_ = dList;
//...
}

I do not understand it. Remember:

DocumentList dList = initDocuments(thesaurus);

for (int i = 0; i < testRuns_; i++)
{
Algo algo = new Algo(dList, 1.1, anzahlCluster, thesaurus, initType_);
run = algo.run(maxIter, epsilon);
tests.add(i, run);
}

In every iteration I am creating a _new_ object "algo" with a _new_
Constructor.

So I do not understand why I have the changes of my DocumentList made by
algo in iteration 1 in my next algo in iteration 2.

How could it be?



Regards,

Re: Question about visibility/ modifications of objects Martin_Pöpping
3/2/2007 4:15:56 PM
justin creasy schrieb:

[quoted text, click to view]

LOL! Sorry please. I am not using the DocumentList control!

The class DocumentList I wrote by myself.
It´s a subclass of ArrayList and manages my Document objects:

public class DocumentList : ArrayList
{
public new Document this[int index]
{
get { return (Document)base[index]; }
}

public override int Add(object document)
{
return base.Add(document as Document);
}
}


So how can I find out if it is call by reference or call by value?


Regards,
Martin
Re: Question about visibility/ modifications of objects Jon Skeet [C# MVP]
3/2/2007 6:03:00 PM
[quoted text, click to view]

<snip>

[quoted text, click to view]

That's completely separate to the fact that it's a reference type.

See http://pobox.com/~skeet/csharp/references.html
(work in progress) and
http://pobox.com/~skeet/csharp/parameters.html
http://pobox.com/~skeet/csharp/memory.html


--=20
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
AddThis Social Bookmark Button