Skip to main content
deleted 365 characters in body
Source Link

when you modify the object, the parameter should be passed as reference in C#

void EditSomething(ref Mytype obj)

that will show that it will modify the object. You should not return the edited object, if you pass it as a parameter anyways. Assuming you are using a ref call.

if you return an object of MyType, I (personally) would expect it to be a new object but I can't point my finger at the "why".

iI guess it's because I would expect to modify the parameter by using a ref call mentioned above.

Also it would look weird:

MyTypevar obj = new MyType();
MyTypevar modifiedobj = EditSomething(obj);

If i see this code, i do not expect obj and modifiedObj to be the same, that's just confusing.

when you modify the object, the parameter should be passed as reference in C#

void EditSomething(ref Mytype obj)

that will show that it will modify the object. You should not return the edited object, if you pass it as a parameter anyways. Assuming you are using a ref call.

if you return an object of MyType, I (personally) would expect it to be a new object but I can't point my finger at the "why".

i guess it's because I would expect to modify the parameter by using a ref call mentioned above.

Also it would look weird:

MyType obj = new MyType();
MyType modifiedobj = EditSomething(obj);

If i see this code, i do not expect obj and modifiedObj to be the same, that's just confusing.

if you return an object of MyType, I (personally) would expect it to be a new object

I guess it's because I would expect to modify the parameter by using a ref call.

Also it would look weird:

var obj = new MyType();
var modifiedobj = EditSomething(obj);

If i see this code, i do not expect obj and modifiedObj to be the same, that's just confusing.

Source Link

when you modify the object, the parameter should be passed as reference in C#

void EditSomething(ref Mytype obj)

that will show that it will modify the object. You should not return the edited object, if you pass it as a parameter anyways. Assuming you are using a ref call.

if you return an object of MyType, I (personally) would expect it to be a new object but I can't point my finger at the "why".

i guess it's because I would expect to modify the parameter by using a ref call mentioned above.

Also it would look weird:

MyType obj = new MyType();
MyType modifiedobj = EditSomething(obj);

If i see this code, i do not expect obj and modifiedObj to be the same, that's just confusing.