c# - Variable sharing inside static method -


I have a question about the variable inside the static method whether the variable inside the static method shares the same memory location Or will they have different memory?

Here is an example.

  public class XYZ {public fixed int (int value) {int b = value; Return b; }}  

If 3 different users execute the call method A,

  XYZ.A (10); XYZ.A (20); XYZ.A (30); At the same time  

What will be the return value of each call?

  XYZ.A (10) =? XYZ.A (20) =? XYZ.A (30) =?  

They are still local variables - the fact that they are not shared between threads They are within a stable method, no matter.

If you used the stable variable as an intermediate variable, then would be unsecured:

  Public class XYZ {// Do not do that! Awesome insecure! Private Static Int B; Public Static Ent A (At Value) {b = Value; Return b; }}  

Here, all threads are actually using the same b variable, so if you call the method together from multiple threads, thread X can write b , after thread Y, so that Thread X is Thread Y.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -