What happens during Array Assignment? Examine MSIL?

T

tom

Hello

I was wondering what happens when one declares 2 arrays:

private object [] arr1;
private object [] arr2;

fills them appropriately and then writes:
arr1 = arr2;

I was wondering if only a reference was changed or if some
copying was occurring.

Also, Im using C#.Net V7.1.3088 in the IDE and was
wondering how I could examine the generated MSIL code to
answer questions like this for myself.

TIA,
Tom.
 
J

Jon Skeet

tom said:
I was wondering what happens when one declares 2 arrays:

private object [] arr1;
private object [] arr2;

fills them appropriately and then writes:
arr1 = arr2;

I was wondering if only a reference was changed or if some
copying was occurring.

Arrays are reference types - only the reference is copied. The two
variables would then refer to the same array, so changes made via one
variable could be seen via the other.
Also, Im using C#.Net V7.1.3088 in the IDE and was
wondering how I could examine the generated MSIL code to
answer questions like this for myself.

You could use ildasm...
 
M

Michael Mayer

tom said:
Also, Im using C#.Net V7.1.3088 in the IDE and was
wondering how I could examine the generated MSIL code to
answer questions like this for myself.

I highly recommend Luts Roeder's Reflector:
http://www.aisto.com/roeder/dotnet/

Very easy to use, powerful, and (for me) stable. There is also a plugin for
vs that uses reflector, but I had poor success with the plug-in. So I just
use the app standalone.

-mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top