views:

375

answers:

3

If you are passing an interface or an instance of a class as a parameter, are we passing many objects or the full vtable, because once you call a method on the instance it need to recurse the vtable and call the appropriate one right?
How does this work?

+1  A: 

You're ultimately passing a pointer to the object, which contains a pointer to the vtable. Well, basically.

OregonGhost
A: 

This is an implementation detail, so I think you shouldn't rely on that !:)

btw, there's no such thing as "passing an interface in parameter". You always pass an object reference which can implement none, one or several interfaces.

Brann
Watch out for some post on Raymond Chen's blog in a few years, because he'll write about some old application that did rely on that!
OregonGhost
@OregonGhost :ahah, very true !
Brann
+5  A: 

You're passing a reference (by value). The exact representation of a reference is implementation-specific, but in most cases it will be a pointer :)

See http://yoda.arachsys.com/csharp/parameters.html for more details.

(I'm on a phone at the moment - if someone could reformat the link that would be helpful :)

Jon Skeet