Jump to content

Recommended Posts

Posted

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

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...