C# parameter passing...

Joined
Jan 10, 2007
Messages
43,898
Location
In The Machine
I pass in an object to a method. This method modifies some properties of the object. After the method returns the changes it made to the object seem to have disappeared as if the object passed in was passed by value rather than reference.

Is there any instance where C# would do such a thing?

This is how I would like write my code:
ResetStopTimes(stops, loadTimes);

private static void ResetStopTimes(Stop[] stops, Dictionary) { ... }

I need to write my code like this in order to get the changes out of the function:
stops = ResetStopTimes(stops, ref loadTimes);

private static Stop[] ResetStopTimes(Stop[] stops, ref Dictionary) { ... }

It's wierd as most places I don't need this hack. It behaves like I would expect it. Anyone know what's going on here?



More...

View All Our Microsoft Related Feeds
 
Back
Top