passing objects in a collection as ref

J

jeff

I have a collection of objects, call them MyObject, that I
store in a Hashtable , myHashTable(with dates as keys for
instance). These are VERY large objects and I have
functions that take them as a 'ref' argument. Now I don't
need to change any of the data in them -- I simply pass
them by ref so that I don't have to make a copy. I have
just discovered that you can't pass properties as 'ref'
arguments because they are read only. So I can't pass
((MyObject) myHashTable[myDate]) as a ref argument to the
function.

How can I maintain a collection of parameterized objects
(by a date or string) that can be passed as a ref argument
to a function.

Thanks,

Jeff.
 
J

jeff

Thanks Jon!

That was very clear. I have been coding in C# for about a
month now and the book I have been using never made that
clear. I thought that since you had to explicitly use
the 'ref' that by default objects (of classes) were
always copied otherwise -- and wasted a lot of time
trying to work around the problem. Now I don't need to
change anything, just delete all the 'ref's in my code!

Cheers,

Jeff.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top