Answer the question
In order to leave comments, you need to log in
How does initializing variables in a C# loop affect performance?
Good evening, C# experts. I asked myself this question: "Does the initialization of variables in the loop affect performance? Or should variables be initialized outside the loop?". Performance is extremely important, as the application is multi-threaded (about 100 threads).
Example 1 (initialization outside the loop):
string response;
for (int i = 0; i < 4; i++)
{
response = Send("DoSomething", "arguments");
}
for (int i = 0; i < 4; i++)
{
string response = Send("DoSomething", "arguments");
}
Answer the question
In order to leave comments, you need to log in
Notice: Undefined property: index::$TestUrl in /home/lucifer/php/Core/modules/router.php on line 29
Notice: Undefined property: index::$Test in /home/lucifer/php/Core/modules/router.php on line 29
"How the initialization of variables in a loop affects performance" is always bad.
On the other hand, you could not be lazy and run both options for 100e6 cycles.
On the third hand, you can read "a rope long enough to shoot yourself in the foot" so that the level of your questions, te-skat, becomes less trivial.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question