Alex Rivera | Logout

can a method parameter pass an object by reference but be read-only?

Asked 2010-08-08T08:58:27.520
19

C#: can you make it so that a method parameter passes an object by reference but is read-only?

eg:

void MyMethod(int x, int y, read-only MyObject obj)

where obj is an object reference but this object cannot be modified during the method.

Can this be achieved in C#?

Edit
Report

1 Answer

0

why don't you make a copy of that object and do whatever you want with that copy while your obj remains not modified.

See here how to clone your object: Deep cloning objects

answered 2010-08-08T09:05:43.297

Your Answer