Is using ref
is bad programming practice? I am doing some refactoring of my old code which actually uses ref a lot. I have turned on code analysis with Microsoft All Rules set and rules say that "Do not pass types by reference"
Cause: A public or protected method in a public type has a ref parameter that takes a primitive type, a reference type, or a value type that is not one of the built-in types.
Why is it really bad? Can I use them in my private methods or internal methods? Using ref in private/internal methods will be good programming practice or nor?
Edit: Here is some samples,
public void DoAutoScrollReverse(Rectangle rectangle, int xPosition, int yPosition,
ref int deltaX, ref int deltaY)
{
}
public bool GetPointCoords(Graphics g, Point pMouse, DisplayBlock2D aBlock,
ref Point3MD pt, ref DisplayPoint2D 2dPoint, ref double gapPos)
{
}
What is happening inside these function is that they are being initialized, set, or whatever.
Update: Why am I using ref? Well actually I am not. Its old code which I need to refactor. I got rid of some of the methods, but complex functions like in second example given I cannot. There is a function which returns bool (tells operation successful or not) and has 3 ref values of different objects. What should I do here? make it private/internal (Is using ref in private/internal good practice?)