P
Peter Kirk
Hi,
I have a method which receives an argument of which I need to change some
values before I use it. But I don't want to alter the object for the caller.
How do I achieve this? Do I need to make a local copy of the obect in my
method, or otherwise "manually" ensure that the object remains unaltered
when my method exits?
For example, see the method below. Here, the caller supplies "anArgument",
which my method alters, but I don't want the caller to see this change -
that is, I want the caller's object to remain unaltered when my method
exits.
public IResult DoSomeStuff( IArg anArgument )
{
IResult result = new MyResult();
anArgument.Value = anArgument.Value + 1;
return result;
}
Thanks,
Peter
I have a method which receives an argument of which I need to change some
values before I use it. But I don't want to alter the object for the caller.
How do I achieve this? Do I need to make a local copy of the obect in my
method, or otherwise "manually" ensure that the object remains unaltered
when my method exits?
For example, see the method below. Here, the caller supplies "anArgument",
which my method alters, but I don't want the caller to see this change -
that is, I want the caller's object to remain unaltered when my method
exits.
public IResult DoSomeStuff( IArg anArgument )
{
IResult result = new MyResult();
anArgument.Value = anArgument.Value + 1;
return result;
}
Thanks,
Peter