One feature which troubled and, and I didn't like in c# is:
When you pass an object to a method, it is by reference by default. If you have worked with c++/VC++/VC.NET, you would definitely not like this feature as we are used to getting more control over the behaviour. We could control when to pass by value and when to pass by reference, but that privilege seemed to have been lost.
This morning we had a tech debate over this feature and thought of digging it further, and here is what we found.
What we were observing was not entirely correct. When we were passing an object and changed its properties/data members within the method, it was reflecting in the calling method after the called method had returned and we concluded that it is always by reference.
There is a small difference here. The object is not passed by reference (yes that's right), it is the properties which are reference. While you can change it's members, you cannot change the actual object itself. And only when you specify ref in the method, the actual object can be changed (can be changed=will be reflected in calling method).
When you pass an object to a method, it is by reference by default. If you have worked with c++/VC++/VC.NET, you would definitely not like this feature as we are used to getting more control over the behaviour. We could control when to pass by value and when to pass by reference, but that privilege seemed to have been lost.
This morning we had a tech debate over this feature and thought of digging it further, and here is what we found.
What we were observing was not entirely correct. When we were passing an object and changed its properties/data members within the method, it was reflecting in the calling method after the called method had returned and we concluded that it is always by reference.
There is a small difference here. The object is not passed by reference (yes that's right), it is the properties which are reference. While you can change it's members, you cannot change the actual object itself. And only when you specify ref in the method, the actual object can be changed (can be changed=will be reflected in calling method).