C# ‘ref’ keyword, performance


If you have a Bitmap object that needs to be passed to numerous methods (about 10), and finally to an event where it shall finally be disposed of after it's used, would it be (performance wise) beneficial to pass it to every one of those methods by reference instead of value?

Passing by value, the object is copied, passing by reference its not.

(Performance is critical in this situation. The application needs to run as fast as possible.)

Best Solution

Bitmap is a reference type. Passing a reference type by value does not copy the object, merely the reference to the object. There would be no performance benefit to passing the Bitmap by reference instead of by value.