Analizer1 kirjoitti:
so When the method is called 3 times from 3 different instances...
Is the method loaded into different memory locations , so each instance has
its own?
Or does the method occupy the same memory address , and all 3 instances
actually use the same Method (executable code)
In C# kind of programs, the code is shared among instances of the class,
but the code is separate. With addition to fields called member fields,
there is "hidden" field named this. So when the code refers to field, like
aField = bField+3
inside the class, actually it does
this.aField = this.bField+3
and when the method starts, this is set to refer to the instance (for
example obj1), so the code actually means
obj1.aField = obj1.bField+3
So, same code can access several instances.
(Actually the first time you refer to the class's method the method ia
loaded into the .NET virtual machine, so you can think that when there
is no instances, there is no code, but when there is one or more
instances, there is one code).
--
Arto Viitanen