Not sure its better. But you could propably get rid of the ref method with
something like:
string temp = (string)array[i];
string result = obj.RefMethod( temp ); // Returns null if no change needed.
if ( result != null )
array[i] = result;
--
William Stacey, MVP
http://mvp.support.microsoft.com
"Brad Wood" <bradley_.wood_@ndsu_.nodak_.edu> wrote in message
news:#ijuQY#2EHA.3596@TK2MSFTNGP12.phx.gbl...[color=blue]
> I have a method that takes a ref string parameter. This is because it
> will be called in loops and most of the time it will not need to modify
> the paramater at all, so I preferred not to return a newly allocated
> string object.
>
> I need to pass items of an array list (can't use specialized collection
> in compact framework) to this method. I can't pass the array item
> directly because I get a compiler error (a ref or out argument must be
> an lvalue). So this is what I'm doing:
> string temp = (string)array[i];
> obj.refMethod ( ref temp );
> array[i] = temp;
>
> I didn't find a performance problem with this, but is there a better way
> to write this?[/color]