Accessing an object by reference

  • Thread starter Thread starter Bruno Panetta
  • Start date Start date
B

Bruno Panetta

Hi, I am a C++ programmer trying to learn C#.
I have a class called Record and am looping through the members of an
object of this class:


foreach (Record.Item BCD in MyRecord.RecordItems)
{
....
BCD.SetItemParameter(3.0);
....
}

The only problem is that the change above does not affect the MyRecord
object, only its copy BCD in the foreach loop. How can I make it do so?
In C++ I could use a reference or a pointer.
I have tried replacing the foreach loop with a for loop but that
doesn't work either. Any suggestions?
Thanks,

Bruno
 
Hi,

IT should work like that, after the loop if you do
MyRecord.RecordItems[0].GetParameter ( ... ) you should get the value you
set inside the loop.

just notice that you are changing a collection insode MyRecord, not MyRecord
itself


cheers,
 
Back
Top