c# - Is there any difference between declare variable in/out for? -
possible duplicate:
declaring variable inside or outside foreach loop: faster/better?
hi all,
what difference between 2 examples or there any?
ex 1:
for (int = 0; < 2; i++) { thread newthread = new thread( ... ); newthread.start(); } ex 2:
thread newthread; (int = 0; < 2; i++) { newthread = new thread( ... ); newthread.start(); } their il codes same...
in second example, can access last thread newthread, not possible in first example.
one more difference: second example holds reference last thread, garbage collector can't free memory when thread finished , disposed.
the new keyword allocates memory, there no difference in memory allocation (see this link).
Comments
Post a Comment