void PassByConstRef( const MyClass& foo ){ // Do something with foo}
public void PassByVal( int n ){ n = 5; // This change is lost to the caller}public void PassByRef( ref int n ){ n = 5; // This change affects the caller}
public void PassByVal( MyClass foo ) // This is by value right? Wrong!{ foo.SomeProperty = 5; // This change affects the caller... doh!}public void PassByRef( ref MyClass foo ){ foo.SomeProperty = 5; // This change affects the caller}
public void PassByVal( MyClass foo ){ foo = new MyClass(); // Caller doesn't get the new MyClass object}public void PassByRef( ref MyClass foo ){ foo = new MyClass(); // Caller does get the new MyClass object}
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.