In C#, I know that by default, any parameters passed into a function would be by copy, that's, within the function, there is a local copy of the parameter. But, what about when an object is passed as parameter to another class?
Would a scenario like the following one be passed by reference or by value:
class MyClass {
private Object localObj;
public void SetObject(Object obj) {
localObj = obj;
}
}
void Main() {
Object someTestObj = new Object();
someTestObj.name = "My Name";
MyClass cls = New MyClass();
cls.SetObject(someTesetObj);
}
In this case, would the class variable localObj
be having the same copy as the someTestObj
created in the Main
driver class? Or would the two variables be pointing to a different object instance?