We have a class variable ArrayList binaryScanData
in a class. In all methods having access to it, we put lock(binaryScanData)
on it because it is shared. Now we want to move one of those methods out to another util class to make it a static
method. We will pass that binaryScanData
into the method like this:
public static void convertAndSaveRawData(ref MemoryStream output, ref ArrayList binaryScanData)
Our questions are followed:
binaryScanData
? can we do the same as it is originally?ref
is necessary? It will only be read in that convertAndSaveRawData
method.The ref isn't necessary, it is only needed if you are going to change the reference itself (ie, assign a new list to it). You can still lock on the object if you like. I recommend locking on SyncRoot
, which I'm not sure if ArrayList has. If not, you might consider moving up to List<T>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With